搜索mysql数据库 [英] search mysql database

查看:117
本文介绍了搜索mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮助,我试图使用html表单搜索my​​sql记录以显示输入主键的相应记录。
这是我的html表单:

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>  

以下是new.php表单操作:,


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);
   ?>

当我输入fname,然后单击输入框时,如何在html输入框中显示hospnum搜索按钮。

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

推荐答案

注意:此脚本原样容易受到sql注入。接下来的代码并不涉及这个问题,因为它超出了原始问题的范围。 不要在生产环境中原样使用此代码。

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.

从PHP跳转到HTML有一个小问题:

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 } ?>

这篇关于搜索mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆