红酒泡绿茶 2014-04-01 12:01
浏览 12

带有一列的SQL - 检查行是否存在

I stuck on something stupid.. I have the table that has only one column. I want to check if there is some value, which I get from the url (method $_GET)

 mysql_connect("localhost", "user", "pass") or die(mysql_error());
 mysql_select_db("db") or die(mysql_error());

 $row=htmlspecialchars($_GET['row']);

 $query = @mysql_query ("SELECT * FROM table WHERE row=$row");


 if ($result = @mysql_fetch_array($query)) { 

 echo "There is that row";
 }


 else {
 echo "There is not that row";
 }

Can you tell me what's wrong?

  • 写回答

3条回答 默认 最新

  • doupi7619 2014-04-01 12:04
    关注

    Obligatory "you should be using PDO" comment.

    You don't say what sort of field it is, maybe it is a text field so it needs to be in quotes.

    $query = @mysql_query ("SELECT * FROM table WHERE row='" . $row . "');
    

    Also if you remove the @ you might get to see some sort of error

    $query = mysql_query ("SELECT * FROM table WHERE row='" . $row . "') or die(mysql_error());
    
    评论

报告相同问题?

悬赏问题

  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表