基本上在设置网页时会出现问题,该网页将接受用户输入的学生 key 。然后这会将学生 key 解析为另一个文件,该文件将针对 mysql 后端运行它以查看该学生已经拥有的记录。但不能让它为我的生活工作,请帮助我在这方面还是个新手。
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("support_log", $con);
$result= mysql_query("SELECT student.first_name, student.surname, student.year_group, student.STKEY, student_log.issue
FROM `student` JOIN `student_log`
WHERE student.STKEY like '$_POST[stkey]'");
$result2 = mysql_query($result) or die("Error: " . mysql_error());
if(mysql_num_rows($result2) == 0){
echo("no records found");
} ELSE {
echo "<table border='1'>
<tr>
<th>First name</th>
<th>Surname</th>
<th>Year Group</th>
<th>Student Key</th>
<th>Issue</th>
</tr>";
while($row = mysql_fetch_array($result2))
{
echo "<tr>";
echo "<td>" . $row['First_Name'] . "</td>";
echo "<td>" . $row['surname'] . "</td>";
echo "<td>" . $row['year_group'] . "</td>";
echo "<td>" . $row['stkey'] . "</td>";
echo "<td>" . $row['issue'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
mysql_close($con);
?>
将我的 where 语句更改为:
WHERE student.STKEY like '$_POST[stkey]'");
我不再收到来自 PHP 的错误,但现在收到错误查询为空,这是我检测是否没有结果的代码的一部分。虽然我已经在 phpmyadmin 中测试了该查询并且它吐出结果。通过查看代码是否有人有任何解决方案?我还通过在 post 命令上运行 echo 来检查解析,以确保输入的数据是正确的。
编辑:摆脱了整个 result2 检查,现在抛出: 警告:mysql_fetch_array() 期望参数 1 为资源,第 24 行 C:\wamp\www\stkey_submit.php 中给出的 bool 值
最佳答案
尝试使用 $_POST['stkey']
而不是 $_POST[stkey]
编辑:如果您在查询中使用它,最好这样做:
$stkey = mysql_real_escape_string($_POST['stkey']);
$sql = "SELECT ....... like '$stkey'";
mysql_query($sql);
关于php - 试图将学生 key 从 html 表单传递到 php 文件以扫描数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10998156/