doushenjia8514 2015-11-28 01:18
浏览 74
已采纳

使用WHERE的SQL语法错误

I'm creating a messaging system for my site and i'm trying to display your friends and i'm having trouble as i'm getting the error:

Select Friend: Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT `user_two` FROM `friends` WHERE (`user_one`='2')' at line 1

Heres My PHP Code:

mysql_connect("************", "*****", "**********");
mysql_select_db("******");

if(isset($_GET['user']) && !empty($_GET['user'])){
   echo "Send Message To " . getuser($_GET['user'], 'first_name');
} else {
   echo "Select Friend: ";
$my_id = $_SESSION['user_id'];
$friend_list = mysql_query("SELECT `user_one` FROM `friends` WHERE (`user_two`='$my_id') OR SELECT `user_two` FROM `friends` WHERE (`user_one`='$my_id')");
if (!$friend_list) { // add this check.
      die('Invalid query: ' . mysql_error());
}
while($run_user = mysql_fetch_array($friend_list)){
    if($run_user['user_one'] == $my_id){
        echo "1";
    } else {
        echo "2";
    }
}
}

And heres my friends table structure:

`id` int(11) AUTO INCREMENT PRIMARY  
`user_one` int(11)   
`user_two` int(11) 

I'm trying to get the friends ID and make sure it isn't mine and then display the information i need to, i am a little bit rusty with SQL so just have that in mind.

  • 写回答

2条回答 默认 最新

  • douzhong8856 2015-11-28 01:33
    关注

    Just remove the brackets on the inside of the query...done

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳