0

我有一个包含三种搜索类型的搜索页面,允许用户通过输入名字根据专业化搜索来搜索最新成员来使用它,每个查询将显示不同的消息和不同的结果

该页面仅显示默认查询
,但 3 种类型不起作用谁能帮助我???

member_search.php

  <?php
// connect to database 
 require_once('include/connect.php'); 
//default  message  on top of the result  display
$querySrting="WHERE registered_date!='' ORDER BY registered_date ASC ";
$queryMSG="Showing newest to oldest memebrs by default";
///IF STATMENT TO DISTINGOUICH SEARCHING
if(isset($_POST['listByq'])
{
  if($_POST['listByq']=="newest_members")
  {
      $querySrting="WHERE registered_date!='' ORDER BY registered_date DESC " or die(mysql_error());
      $queryMSG="Showing senior to oldest memebrs";
  }
elseif($_POST['listByq']=="by_specialization")

   {
      $querySrting="WHERE specialization! = '' ORDER BY user_id DESC" or die(mysql_error());
      $queryMSG="showing members with specs";
   }
elseif($_POST['listByq']=="by_firstname")
  {
      $fname = $_POST['fname'];
      $fname = stripcslashes($fname);
      $fname = strip_tags($fname);
      $querySrting="WHERE  first_name LIKE '%$fname%'"or die(mysql_error());
      $queryMSG="Showing member with the name you searched for";
  }
}
///******query the member data using the queryString*******//
$sql = mysql_query("SELECT user_id, first_name, last_name, birth_date, registered_date FROM user $querySrting") or die(mysql_error());
 //**********************outputlist*********************************//
 $outputlist="";
 while($row = mysql_fetch_array($sql))
 {
     $id=$row['user_id'];
     $firstname=$row['first_name'];
     $lastname=$row['last_name'];
     $birthdate=$row['birth_date'];
     $registereddate=$row['registered_date']; 
     ////***********for the upload image*************************//
      $check_pic="members/$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="3"><div style="height:120px;overflow:hidden;"><a href = "http://localhost/newadamKhoury/profile.php?user_id='.$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='.$id.'" target="_blank">'.$firstname.' '.$lastname.'</a></td>
                  </tr>

                  <tr>
                    <td><div align="right">Birth date:</div></td>
                    <td>'.$birthdate.'</td>
                  </tr>
                  <tr>
                   <td><div align="right">Registered:</div></td>
                   <td>'.$registereddate.'</td>
                  </tr>
                  </table>
                  <hr />
          ';

 }//close while

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="keywords" content="" />
<meta name="description" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Lam_El_Chamel</title>
<link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css' />
<link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css' />
<link href="default.css" rel="stylesheet" type="text/css" media="all" />
<!--[if IE 6]>
<link href="default_ie6.css" rel="stylesheet" type="text/css" />
<![endif]-->
</head>
<body>
<div id="banner">
  <div class="img-border">
    <div id="header-wrapper">
      <div id="header">

        <div id="logo">
          <marquee width="80%" behavior="scroll" direction="left" onmouseover="this.stop();" onmouseout="this.start();">
            <h1><b>Social media</b></h1>
          </marquee>
        </div>

            <?php /*require_once('login.php')*/; ?>
      </div>
    </div>

    <a href="#"><img src="images/web_header copy.jpg" width="1121" height="210" alt="" /></a></div>
</div>
<div id="wrapper">
    <div id="page-wrapper">
        <div id="page">
            <div id="wide-content">


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

                  Browse Newest Members
                    <input type="submit" name="button" id="button" value="go" />
                    <input type="hidden" name="listbyq" value="newest_members" />
                  </form></td>
                  <td width="28%"><form id="form2" name="form2" method="post" action="member_search.php">
                    Search By specialization
                    <input type="submit" name="button2" id="button2" value="go" />
                    <input type="hidden" name="listbyq" value="by_specialization" />
                  </form></td>
                  <td width="43%"><form id="form3" name="form3" method="post" action="member_search.php">
                    Search By firstname
                    <label>
                    <input type="text" name = "fname" id="fname" />
                    </label>
                    <input type="submit" name="button3" id="button3" value="go" />
                    <input type="hidden" name="listbyq" value="by_firstname" />
                  </form></td>
                </tr>
              </table>
              <br />
              <table width="70%" align="center">
                <tr>
                  <td><?php print "$queryMSG";  ?>
                         <br />
                      <?php print "$outputlist";  ?>
                   </td>
                </tr>
              </table>
              <h2>&nbsp;</h2>
            </div>
            </div>
        </div>
  </div>
</div>
<?php /*require_once('footer.php');*/ ?>


</body>
</html>
4

2 回答 2

0

你的 if 条件错误

if(isset($_POST['listByq'])=="newest_members")

把它改成这样

if(isset($_POST['listByq'])) {

 if ($_POST['listByq']=="newest_members") {

    $querySrting="WHERE registered_date!='' ORDER BY registered_date DESC " or die(mysql_error());
    $queryMSG="Showing senior to oldest memebrs";
 }
}
于 2013-05-10T12:58:14.950 回答
0

您的 HTML 是:

<input type="hidden" name="listbyq" value="newest_members" />

但是你的 PHP 是:

if($_POST['listByq']=="newest_members")

字段名不匹配,因为大小写不一样;POST 变量有一个大写的“B”。

您只需要重命名表单或 PHP 中的字段,以便两个集合匹配。

于 2013-05-10T13:20:42.887 回答