MySQL Numrows 期望参数
MySQL Numrows Expecting Parameter
所以我得到了错误:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\All Connected\profile.php on line 117
在尝试检查好友请求状态信息时,我看到有人使用 MySQL 错误转储或类似的东西来修复此问题,但我不确定,我能得到一些帮助吗?
这是我的代码片段,只有需要修复的部分
mysql_connect("illuzionz-pc", "-----", "----------");
mysql_select_db("allcon");
$my_id = $_SESSION['user_id'];
$profile_id = $_GET['id'];
$check_friend_query = mysql_query("SELECT id FROM friends WHERE (user_one='$my_id' AND user_two='$profile_id') OR (user_one='$profile_id' AND user_two='$my_id')");
if(mysql_num_rows($check_friend_query) == 1){
echo "<br><a class='pure-button pure-button-disabled' href='#'>Already Friends!</a><br>";
echo "<a class='button-error pure-button' href='#'>Unfriend {$user['first_name']}</a>";
} else {
mysql_connect("illuzionz-pc", "Admin", "0A562B0CA0");
mysql_select_db("allcon");
$my_id = $_SESSION['user_id'];
$profile_id = $_GET['id'];
$from_query = mysql_query("SELECT `id` FROM `friend_req` WHERE `from`='$profile_id' AND `to`='$my_id'");
$to_query = mysql_query("SELECT `id` FROM `friend_req` WHERE `from`='$my_id' AND `to='$profile_id'");
if(mysql_num_rows($from_query) == 1){
echo "<a class='button-secondary pure-button' href='#'>Ignore Friend Request</a><br>";
echo "<a class='button-success pure-button' href='#'>Accept Friend Request</a>";
} else if(mysql_num_rows($to_query) == 1){
echo "<a class='button-error pure-button' href='#'>Cancel Friend Request</a>";
} else {
echo "<a class='pure-button pure-button-primary' href='#'>Send Friend Request</a>";
}
}
您的 mysql_query
已返回 false
,因为您传递的无效 SQL。
将您的 $to_query 修正为:
$to_query = mysql_query("SELECT `id` FROM `friend_req` WHERE `from`='$my_id' AND `to`='$profile_id'");
所以我得到了错误:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\All Connected\profile.php on line 117
在尝试检查好友请求状态信息时,我看到有人使用 MySQL 错误转储或类似的东西来修复此问题,但我不确定,我能得到一些帮助吗?
这是我的代码片段,只有需要修复的部分
mysql_connect("illuzionz-pc", "-----", "----------");
mysql_select_db("allcon");
$my_id = $_SESSION['user_id'];
$profile_id = $_GET['id'];
$check_friend_query = mysql_query("SELECT id FROM friends WHERE (user_one='$my_id' AND user_two='$profile_id') OR (user_one='$profile_id' AND user_two='$my_id')");
if(mysql_num_rows($check_friend_query) == 1){
echo "<br><a class='pure-button pure-button-disabled' href='#'>Already Friends!</a><br>";
echo "<a class='button-error pure-button' href='#'>Unfriend {$user['first_name']}</a>";
} else {
mysql_connect("illuzionz-pc", "Admin", "0A562B0CA0");
mysql_select_db("allcon");
$my_id = $_SESSION['user_id'];
$profile_id = $_GET['id'];
$from_query = mysql_query("SELECT `id` FROM `friend_req` WHERE `from`='$profile_id' AND `to`='$my_id'");
$to_query = mysql_query("SELECT `id` FROM `friend_req` WHERE `from`='$my_id' AND `to='$profile_id'");
if(mysql_num_rows($from_query) == 1){
echo "<a class='button-secondary pure-button' href='#'>Ignore Friend Request</a><br>";
echo "<a class='button-success pure-button' href='#'>Accept Friend Request</a>";
} else if(mysql_num_rows($to_query) == 1){
echo "<a class='button-error pure-button' href='#'>Cancel Friend Request</a>";
} else {
echo "<a class='pure-button pure-button-primary' href='#'>Send Friend Request</a>";
}
}
您的 mysql_query
已返回 false
,因为您传递的无效 SQL。
将您的 $to_query 修正为:
$to_query = mysql_query("SELECT `id` FROM `friend_req` WHERE `from`='$my_id' AND `to`='$profile_id'");