基本的に、ユーザーが入力した学生キーを取り込む Web ページの設定に問題があります。これにより、生徒のキーが別のファイルに解析され、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 からエラーを受信しなくなりましたが、結果がないかどうかを検出するコードの一部である Query was empty というエラーを受信しました。私はphpmyadminでそのクエリをテストしましたが、結果を吐き出しました。コードを見て、誰かが解決策を持っていますか? また、post コマンドで echo を実行して解析をチェックし、入力されたデータが正しいことを確認しました。
編集: スローする result2 チェック全体を取り除きました: 警告: mysql_fetch_array() は、パラメーター 1 がリソースであると想定しています。