nit*_*ous 5 php mysql syntax-error mysql-error-1064
我正在尝试调试我的代码,但mysql_error()没有显示任何内容.我知道有些不对劲,因为我写的时候
or die("ERROR");
Run Code Online (Sandbox Code Playgroud)
它显示ERROR.所以问题必须是那一行代码.当我写作
or die(mysql_error());
Run Code Online (Sandbox Code Playgroud)
它显示空白.这是我认为有错误的行的代码:
while ($rows = mysql_fetch_array($sql6) or die(mysql_error())) {
Run Code Online (Sandbox Code Playgroud)
现在这里是完整的代码块:
$sql6 = mysql_query("SELECT * FROM replies WHERE thread_id = $thread_id");
$numRows = mysql_num_rows($sql6);
$replies = '';
if ($numRows < 1) {
$replies = "There are no replies yet, you can make the first!";
} else {
while ($rows = mysql_fetch_array($sql6) or die(mysql_error())) {
$reply_content = $rows['5'];
$reply_username = $rows['7'];
$reply_date = $rows['8'];
$reply_author_id = $rows['4'];
$sql9 = mysql_query("SELECT * FROM users WHERE id = '$reply_author_id'");
$numRows = mysql_num_rows($sql9);
if ($numRows < 1) {
while ($rows = mysql_fetch_array($sql9)) {
$reply_user_fn = $rows['first_name'];
$reply_user_ln = $rows['last_name'];
$reply_user_id = $rows['id'];
$reply_user_pp = $rows['profile_pic'];
$reply_user_lvl = $rows['user_level'];
$reply_user_threads = $rows['threads'];
$reply_user_email = $rows['email'];
$replies .= '<tr><td valign="top" style="border: 1px solid black;">';
$replies .= '<div class="reply" style="min-height: 125px;"';
$replies .= '<h2>Re: ' . $thread_title . '</h2><br />';
$replies .= '<em>by: ' . $reply_username . ' - ' . $reply_date . '</em><hr />';
$replies .= $reply_content;
$replies .= '</div></td>';
$replies .= '<td valign="top" width="200" align="center" style="border: 1px solid black;"';
$replies .= '<img src="userdata/profile_pics/' . $reply_user_pp . '" width="80" height="80"><br />';
$replies .= '<a href="profile.php?u=' .$reply_username . '" style="color: black;">'. $reply_username .'</a><br />';
$replies .= '<a href="profile.php?u=' .$reply_username . '" style="color: black;">' . $reply_user_fn.' ' .$reply_user_ln . '</a><br />';
$replies .= 'Threads: ' . $reply_user_threads . ' <br />Level: '. $reply_user_lvl .'<br />Sign up date: ' . $reply_user_email/*PUT SIGNUP DATE*/ .'';
$replies .= '<input type="button" name="addfriend" value="Add Friend">';
$replies .= '</td>';
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我做错了什么,为什么PHP不显示mysql错误?谢谢
不要放在or die()循环条件内.循环条件变为false表示循环结束的信号,并且die() 每次循环完成时也会触发.
mysql_fetch_row()当没有更多行时返回false这是触发您的die()语句的内容,尽管没有错误.
您可以使用try..catch块来了解代码无法正常工作的原因,如下所示:
try {
while ($rows = mysql_fetch_array($sql6)) {
// your code ..
}
} catch (Exception $e) {
echo $e->getMessage();
echo "---";
echo mysql_error();
}
Run Code Online (Sandbox Code Playgroud)
请注意,正如您所说,or die正在执行,这意味着您的代码中某处存在错误,而不是mysql error. 因此,上面的代码将捕获该异常并为您显示它。此外,mysql_error如果在该点之前发生过任何 ,它还会显示任何 ,以供参考,以便您可以比较两个字符串。
| 归档时间: |
|
| 查看次数: |
35610 次 |
| 最近记录: |