开发者

search mysql database

Please help, Im trying to search for mysql records using an html form to display the corresponding record for the entered primary key. Here's my html form:

<td><input type="submit" name="Submit" value="Search"></td>  

And here's the new.php form action:,

mysql_select_db("Hospital", $con);
   $result = mysql_query("SELECT HOSPNUM FROM t2 WHERE FIRSTNAME='{$_POST["fname"]}'");

 while($row = mysql_fetch_array($result))
 {
   <input name="hnum" type="text" id="hospnum" value="<?php echo $row['HOSPNUM']; ?>"  开发者_运维知识库      />
   }
mysql_close($con);
   ?>

How do I get to display the hospnum in the html inputbox when I input the fname and then click the search button.


Note: This script, as-is, is vulnerable to sql-injections. The code that follows is not dealing with this, as it's out of the scope of the original question. Do not use this code as-is in a production environment.

You have a small problem jumping from PHP to HTML:

<?php

   mysql_select_db("Hospital", $con) or die(mysql_error());
   $fname = $_POST["fname"];
   $result = mysql_query("SELECT HOSPNUM FROM t2 WHERE FIRSTNAME='{$fname}'");

?>

<h3>Results:</h3>

<?php while ( $row = mysql_fetch_array($result) ) { ?>

  <input type="text" name="hnum" value="<?php echo $row["HOSPNUM"]; ?>" />

<?php } ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜