[英]Display row in mysql table when a user enter id
I want to display a row when a user enter his id and after submit. 我想在用户输入ID并提交后显示一行。 My code is not working correctly.
我的代码无法正常工作。 Please rectify this.
请纠正这一点。
search-form.php is looking like this. search-form.php看起来像这样。
</html><body>
<form method="GET" action="search.php">
Keyfield <input type="text" name="search"> <br><br>
<input type="submit" value="submit">
</form></body>
</html>
and 和
search.php looking like this. search.php看起来像这样。
<?php
$connection = mysql_connect('localhost','user','pass') or die ("Couldn't connect to server.");
$db = mysql_select_db('db', $connection) or die ("Couldn't select database.");
$search=$_GET['search'];
$fetch = 'SELECT * FROM `table` WHERE `ID` = "'.$search.'"';
echo "<table margin=auto width=999px border=1>";
echo "<tr><td><b>ID</b></td><td><b>Name</b></td><td><b>Telephone</b></td><td> <b>E-mail</b></td><td><b>Couttry Applying for</b></td><td><b>Visa-Category</b> </td><td><b>Other Category</b></td><td><b>Passport No</b></td><td> <b>Remarks</b></td></tr>";
for($i=0;$i<$num;$i++)
{
$row=mysql_fetch_row($fetch);
echo "<tr>";
echo"<td>$row[0]</td>";
echo"<td>$row[1]</td>";
echo"<td>$row[2]</td>";
echo"<td>$row[3]</td>";
echo"<td>$row[4]</td>";
echo"<td>$row[5]</td>";
echo"<td>$row[6]</td>";
echo"<td>$row[7]</td>";
echo"<td>$row[8]</td>";
echo"</tr>";
}//for
echo"</table>";
?>
Display when a user enter his id and submit. 当用户输入其ID并提交时显示。 But this code doesn't display row with id.
但是此代码不显示带有id的行。 Rectify this.
纠正这个。 Thanks.
谢谢。
you are missing mysql_query statement.You should execute the query before fetching the result modify like $sql= 'SELECT * FROM table
WHERE ID
= "'.$search.'"'; 您缺少mysql_query语句。应在获取结果修改之前执行查询,例如$ sql ='SELECT * FROM
table
WHERE ID
=“'。$ search。'”'; $fetch = mysql_query($sql); $ fetch = mysql_query($ sql);
A few points: 几点:
$fetch = 'SELECT * FROM
table WHERE
ID = "'.$search.'"'
leads to the most common and severe security flaw : SQL injection. $fetch = 'SELECT * FROM
table WHERE
ID = "'.$search.'"'
导致最常见和最严重的安全漏洞:SQL注入。 Please read about this (google) About point 3, assuming the fact that you will use PDO, please read http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html 关于第3点,假设您将使用PDO,请阅读http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.