首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sql查询导致php中的错误

问sql查询导致php中的错误
EN

Stack Overflow用户
提问于 2015-02-19 14:18:08
回答 4查看 63关注 0票数 0

我试图在php中运行这个sql查询,但是我得到了一个错误,我的查询是错误的。请帮帮忙

代码语言:javascript
复制
<?php
    @include("dbcon.php");
    $last_date = $_POST['lastdate'];
    $page_rows=3;
    $result = mysql_query("SELECT  * from events where dated < $last_date order by dated desc limit $page_rows") or die(mysql_error());
    //for testing
    echo $result;
?>
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-02-19 14:21:26

我认为这是因为您的$last_date ..It应该在单引号中'',这应该有效。

代码语言:javascript
复制
$result = mysql_query("SELECT  * from events where dated < '$last_date' order by dated desc limit $page_rows")  or die(mysql_error());
票数 0
EN

Stack Overflow用户

发布于 2015-02-19 14:21:37

如果它唯一的语法错误,请尝试如下。

代码语言:javascript
复制
<?php
    @include("dbcon.php");
    $last_date = $_POST['lastdate'];
    $page_rows=3;
    $result = mysql_query("SELECT  * from events where dated < '$last_date' order by dated desc limit '$page_rows'") or die(mysql_error());
    //for testing
    echo $result;
    ?>
票数 0
EN

Stack Overflow用户

发布于 2015-02-19 14:25:14

加单引号就行了。使用下面的代码

代码语言:javascript
复制
<?php
@include("dbcon.php");
$last_date = $_POST['lastdate'];
$page_rows=3;
$result = mysql_query("SELECT  * from events where dated < '$last_date' order by dated desc limit $page_rows") or die(mysql_error());
//for testing
echo $result;
?>

希望这对你有帮助

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28608679

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档