2013-05-18 40 views
2

我有一個搜索頁面,允許用戶甚至搜索使用3個選項隱藏的輸入類型不工作

搜索有關使用3種類型的其他成員

和我使用一種形式和一個按鈕爲所有三種類型與3個不同的隱藏值

但問題是系統在選擇省時不採取行動

所以任何人都可以幫助我嗎?

代碼:

<?php 
//**********search by locationn***************************************// 
if(isset($_POST['listbyq'])) 
{  
//********************by governorate**************************************// 
    if($_POST['listbyq']=="by_gov") 
    { 
     $bygov = $_POST['governorate']; 
     $sql = mysql_query("SELECT user_id,first_name, last_name, birth_date, registered_date, governorate_name 
         FROM members u INNER JOIN governorate g 
         ON u.governorate = g.governorate_id WHERE governorate = '$bygov'")or die(mysql_error("Error: querying the governorate")); 

     $num_row = mysql_num_rows($sql); 
     if($num_row > 0) 
     { 
      while($row = mysql_fetch_array($sql)) 
      { 
       $row_id = $row['user_id']; 
       $row_first_name = $row['first_name']; 
       $row_last_name = $row['last_name']; 
       $row_birthdate = $row['birth_date']; 
       $row_registered_date = $row['registered_date']; 
       $row_gov = $row['governorate_name']; 

       ////***********for the upload image*************************// 
     $check_pic="members/$row_id/image01.jpg"; 
     $default_pic="members/0/image01.jpg"; 
     if(file_exists($check_pic)) 
     { 
      $user_pic="<img src=\"$check_pic\"width=\"120px\"/>"; 
     } 
     else 
     { 
      $user_pic="<img src=\"$default_pic\"width=\"120px\"/>"; 
     } 

      $outputlist.=' 
    <table width="100%"> 
       <tr> 
        <td width="23%" rowspan="4"><div style="height:120px;overflow:hidden;"><a href =    "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$user_pic.'</a></div></td> 
        <td width="14%"><div align="right">Name:</div></td> 
        <td width="63%"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$row_id.'" target="_blank">'.$row_first_name.' '.$row_last_name.'</a></td> 
        </tr> 

        <tr> 
         <td><div align="right">Birth date:</div></td> 
         <td>'.$row_birthdate.'</td> 
        </tr> 
        <tr> 
        <td><div align="right">Registered:</div></td> 
        <td>'.$row_registered_date.'</td> 
        </tr> 

        <tr> 
        <td><div align="right">Governorate</div></td> 
        <td>'.$row_gov.'</td> 
        </tr> 
        </table> 
        <hr /> 
      '; 

      } 
     } 

    } 
} 
else 
{ 
    $errorMSG = "No Member has the listed location!!"; 
} 
?> 

HTML代碼

<table width="94%" height="63"> 
       <tr> 
        <td width="29%"><form id="form1" method="post" action="member_search2.php"> 

        <h3>Search by Location</h3><br /> 
        <?php require_once('location_fields.php'); ?> 
        <input type="hidden" name="listbyq" value="by_gov" /> 
        <input type="hidden" name="listbyq" value="by_dist" /> 
        <input type="hidden" name="listbyq" value="by_city" /> 
        <input type="submit" name="searchbylocation" id="button" value="go" /> 
        </form></td> 
</tr> 
</table> 
+0

何處啓動form標籤? ...你的3個隱藏的輸入具有相同的名稱。 –

+0

旁邊的TD他們是一個窗體標籤 – LebDev

回答

0

這是因爲你被分配相同的名字給你所有的輸入字段name="listbyq",所以改名爲其中的不同,所以你可以檢索在不同的變量

<input type="hidden" name="listbyq" value="by_gov" /> 
<input type="hidden" name="listbyqa" value="by_dist" /> 
<input type="hidden" name="listbyqb" value="by_city" /> 

現在你可以分別在你的if所陳述

if($_POST['listbyq'] == 'by_gov') 
if($_POST['listbyqa'] == 'by_dist') 
if($_POST['listbyqb'] == 'by_city') 

然後我想記住你,mysql_功能已被棄用,所以我會建議你切換到mysqliPDO而事實上你是在sql injection風險,這裏有How can I prevent SQL injection in PHP?看看。您應該使用準備好的陳述來避免任何風險

+0

ohhh好的,但問題是,我只是寫了**部分的**政府**,但即使這不起作用 – LebDev

+0

@ user2396708嘗試改變形式,因爲我說,並運行給一部分,讓我們看看它是否工作,現在你不會ovveride值兩次 – Fabio

+0

謝謝你這是它覆蓋的問題 – LebDev