php从数据库中选择不显示正确的结果

时间:2015-05-22 17:18:37

标签: php mysql

这是我的代码,用于显示我从数据库中获取的数据但是当我从2条件中选择时它没有显示任何内容

<form action="sebelum_tempah.php" method="post" >
    <div align="center"><span class="style16 style17">Enter I/C Number</span>
        <input name="noic" type="text" size="15" value="" id="" />
        </span>
        <input name="Submit10" type="submit" class="style16" value="SAH" />
    </div>
    <label>
    <div align="center"><br />
        <br />
    </div>
    </label>
    <table width="500" border="1" align="center" cellpadding="3" cellspacing="0">
      <tr bgcolor="#FF6600">
        <th width="117" bgcolor="#006699" scope="row">Name</th>
        <th width="73" bgcolor="#006699" scope="row">No I/C </th>
        <th width="80" bgcolor="#006699" scope="row">No Phone </th>
        <th width="110" bgcolor="#006699" scope="row">Please click below</th>
      </tr>
      <?php 
include "conn.php";
if($_POST){
$sql= "SELECT bil,noic,nama,notel FROM user WHERE noic='_POST[noic]'";
$result=mysql_query($sql,$db_conn);
$i=0;
while ($row=mysql_fetch_array($result)){

$i++;                                           
?>

      <tr>
       <th scope="row"><?php echo $row{'nama'};?></th>
        <th scope="row"><?php echo $row{'noic'}; ?></th>
        <th scope="row"><?php echo $row{'notel'}; ?></th>
        <th scope="row"><a href="semasa_tempah.php?bil=<?php echo $row['bil'];?>" target="_self">Reserve</a></th>
    </tr>
      <?php }
}
mysql_close($db_conn);
?>
    </table>

  </form>

我得到了结果,但是当我遇到2个条件相遇时,就像是noic是人名

$sql= "SELECT bil,noic,nama,notel FROM user WHERE noic='_POST[noic]' AND nama='_POST[nama]'";

不显示任何内容

1 个答案:

答案 0 :(得分:0)

进行以下更改并尝试。

$sql= "SELECT bil,noic,nama,notel FROM user WHERE noic='$_POST[noic]'";



<tr>
       <th scope="row"><?php echo $row['nama'];?></th>
        <th scope="row"><?php echo $row['noic']; ?></th>
        <th scope="row"><?php echo $row['notel']; ?></th>
        <th scope="row"><a href="semasa_tempah.php?bil=<?php echo $row['bil'];?>" target="_self">Reserve</a></th>
    </tr>