【发布时间】:2012-01-18 14:37:43
【问题描述】:
我尝试从文本框中获取值,但失败了。 这是我的代码。你想要的是从文本框中获取值并将值与我的数据库中的值匹配
<form action="" method="post">
<strong>Code: *</strong> <input type="text" name = "code" >
<input type="submit" name="submit" value="Submit">
</form>
<?php
$code= $_POST["code"];
$sql = "SELECT bookingref FROM starpick";
$result = $mysqli->query($sql);
while (list($bookingref )=$result->fetch_row())
{
if (($bookingref == $code) )
{
echo "Sorry, there was a problem uploading your file.";
}else
{
echo "==";
}
}
?>
【问题讨论】:
-
考虑在你的 sql 中添加 WHERE 子句?
-
您的代码无条件运行,无论表单是否提交,都执行 PHP 代码。