尝试获取特定日期的费用列表,我可以在PHPMyAdmin中执行此SQL罚款,但是在页面上我收到MYSQL语法错误。

代码:

$full_date = date('d M Y', strtotime($date));

$get_expenses = mysql_query("SELECT Sum(cost) AS expense FROM expenses WHERE date = $full_date")or die(mysql_error());

$expenses = mysql_fetch_array( $get_expenses );

echo $expenses['expense'];


我收到的语法错误是:


  您的SQL语法有误;检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的“ Apr 2015”附近使用


我检查了一下$expenses['expense']的值,它返回了一个有效的日期。在PHPMyAdmin中,我可以毫无问题地执行此SQL。有指针吗?干杯!

最佳答案

尝试这样,在将您的日期转换成相应的格式之前,请像这样,

$get_expenses = mysql_query("SELECT Sum(cost) AS expense FROM expenses WHERE date = '$full_date'")or die(mysql_error());

10-06 07:36