duan19780629 2016-03-11 14:23
浏览 76

php / sql AND语句不起作用

I have my code:

$db_date2;
$today2 = date("Y-m-d");
        $sql1 = "SELECT * FROM todays_spend WHERE id =$user_id_session AND date=$today2";
        $date_records = mysql_query($sql1); 
        while($today_trip=mysql_fetch_assoc($date_records)){
        $db_date2 = $today_trip['date'];    
        }
        echo $db_date2;

It is saying "Undefined variable: db_date2". When I remove the AND statement it works. Am I doing the AND statement wrong? the 'date' field in my database is also saved in the format Y-m-d.

also tried the single qoutes '' around the variables, still not working!

  • 写回答

3条回答 默认 最新

  • doupeng3501 2016-03-11 14:24
    关注

    You need to write single quote'' around your variable.

    Write your query as below:-

    $sql1 = "SELECT * FROM todays_spend WHERE id ='$user_id_session' AND date='$today2'";
    

    Warning

    mysql_* was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used

    Hope it will help you :-)

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算