我现在已经有了数据库拉取结果,但是它将它们拉到PHP脚本页面(test.php)上。我想在名为'DOB'和'email'的表单框中显示结果。在同一页上显示回显数据库结果
表单页面:
<form id="form_53" name="login" action="test.php">
<input type="text" name="username">
<input type="text" name="DOB">
<input type="text" name="email">
<input type="submit" style="position:absolute;>
</form>
PHP:
<?php
$host=""; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name=""; // Table name
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$username = $_POST['username'];
echo '</br>';
$query = mysql_query("SELECT * FROM `members` WHERE `username`='$username'");
while($result = mysql_fetch_array($query)) {
//display
echo $result['DOB']; //I want this displayed on the 'DOB' form box
echo $result['email']; //I want this displayed on the 'email' form box
}
?>
只是你不应该使用尖mysql_功能,因为他们不支持,也该代码对mysql注入非常开放。 – lemondrop 2013-04-30 00:17:42
我该如何解决这个问题,对不起我是PHP新手 – 2013-04-30 00:18:53
使用诸如PDO之类的引擎将消除mysql注入的可能性,并且它仍然受支持。你可以在这里阅读更多:http://stackoverflow.com/questions/60174/how-to-prevent-sql-injection-in-php – lemondrop 2013-04-30 00:20:33