2013-12-16 3 views
0

PHP와 HTML 코딩에 익숙하지 않아서 매우 유감스럽게 생각합니다.

내 문제는 다음과 같습니다. 일단 사용자가 로그인하여 웹 사이트의 홈페이지로 이동하면 양식의 제출을 ​​클릭하기 전에 $str_result$str_comments이 표시됩니다. 이 // Your code here to handle a successful verification 말한다 어디 당신은 실제로 if()를 작성해야

<?php 
//If connected to the database get services names from database and write out DropDownMenu 
     mysqli_select_db($db_server, $db_database); 
     $query = "SELECT ID, Name FROM categories ORDER BY Name"; 
     $result = mysqli_query($db_server, $query); 
     if (!$result) die("Query failed: " . mysqli_error($db_server)); 

     while($row = mysqli_fetch_array($result)){ 
       $str_options .= "<option value= '" . $row[ 'ID'] . "'>"; 
       $str_options .= $row['Name']; 
       $str_options .= "</option>"; 
     } 
     mysqli_free_result($result); 

// Your code here to handle a successful verification 
$str_result = "<h2>Thanks for your search! Services avaliable are:" . 
$category = clean_string($db_server, $_POST["categories"]) . "</h2>"; 
?> 

<!--form--> 
<form method="post" action="nihome.php"><p>I am searching for</p> 
<select name="categories"><?php echo $str_options; ?></select> 
<br /> 
<input type="submit" id="submit" name="submit" value="Submit" /> 
</form> 

<?php 
//Capture form data, if anything was submitted 
if (isset($_POST['categories']) and ($_POST['categories'] != '')){ 
$category = clean_string($db_server, $_POST['categories']); 

// create the SQL query 
$query = "SELECT salon.ID AS ID, categories.Name as Category, salon.salon_name AS Salon, services.name AS Service, servicesoffered.price AS price FROM services 
    JOIN categories ON services.cID = categories.ID 
    JOIN servicesoffered ON servicesoffered.serviceID = services.ID 
    JOIN salon ON servicesoffered.salonID = salon.ID WHERE categories.ID=$category"; 
        // query the database 
        mysqli_select_db($db_server, $db_database); 
        $result = mysqli_query($db_server, $query); 
        if (!$result) die("Database access failed: " . mysqli_error($db_server)); 

// if there are any rows, print out the contents 
while ($row = mysqli_fetch_array($result)) { 
$str_result .= '<h3>' . $row['Salon'] . ',</h3><p>' . 
      $row['Service'] . ", £" . 
      $row['price'] .'</p>' .<a href="salonpage.php?salonid=' . $row['ID'] .'">Click here to view or add to salon reviews</a>'; 

} 
if($str_result == "") $str_result = "<h2>No services found</h2>"; 

} else { 
$str_result = '<h2>No service was requested</h2>'; 
} 
mysqli_close($db_server); 

echo $str_result; 
echo $str_comments; 
?> 

답변

0

:

내 코드입니다 게다가, 당신이 놓치고있는

if (!empty($_POST) /* && all your other validation routines */) 
    { 
    $str_result = "<h2>Thanks for your search! Services avaliable are:" . 
    $category = clean_string($db_server, $_POST["categories"]) . "</h2>"; 
    } 

' 상기 <a href="salonpage.php?

0

전 스크립트 시작 부분에서 다음과 같이 설정합니다.

$str_result = "<h2>Thanks for your search! Services avaliable are:" 

(10)는

(또한, 그 줄에 후행 점이있다, propably ; 있어야) 그리고 당신은 다음을 확인

이 결코 없기 때문에 물론, 일이 결코
if($str_result == "") $str_result = "<h2>No services found</h2>"; 

빈 문자열.

당신이 할 경우 마지막에이 당신의 if 문 같은 것이 제대로 발사해야하고, 당신이 예상 된 결과와 끝까지해야합니다

$str_result = ""; 

[ ... ] 

if (isset($_POST['categories']) and ($_POST['categories'] != '')){ 
    // Set it inside this if statement. 
    // So it will stay empty when nothing was submitted 
    $str_result = "<h2>Thanks for your search! Services avaliable are:" 
+0

완벽하게 작동합니다! 고맙습니다. 완전한 손실! – user3095683

0

당신이 여기 두이

if($str_result == "") 
{ $str_result = "<h2>No services found</h2>"; 

} else { 
$str_result = '<h2>No service was requested</h2>'; 
} 
mysqli_close($db_server); 

echo $str_result; 
echo $str_comments; 
} 

를 시도해야한다 사물은 매우 중요합니다.
첫째 :

if($str_result == "") 
    { $str_result = "<h2>No services found</h2>"; 

    } 

당신은 잊어 {
두 번째 시작 :
당신이 버튼을 클릭 할 때만 실행하게됩니다

echo $str_result; 
    echo $str_comments; 

} 내부에 보관해야합니다. 희망이 당신이 <a href=........>'

`$row['price'] .'</p>' .'<a href="salonpage.php?salonid=' . $row['ID'] .'">Click here to view or add to salon reviews</a>'; 

및 캡슐화 $str_result$str_comments 전에 작은 따옴표를해야 ;

0

먼저 올바른이 줄
그리고

$str_result = "<h2>Thanks for your search! Services avaliable are:" ; 

말을하는 데 도움이isset에있는 경우 categories 변수가있는 경우에만 나타납니다.

0

if 조건 안에 코드를 넣어야합니다.

즉,도

if (!empty($_POST){ 
if($str_result == "") $str_result = "<h2>No services found</h2>"; 
} else { 
$str_result = '<h2>No service was requested</h2>'; 
} 
} 

, 당신은 '당신이 누락있는 <a href="salonpage.php?

관련 문제