【问题标题】:Difficulty running my code in web host难以在网络主机中运行我的代码
【发布时间】:2015-06-22 08:23:22
【问题描述】:

目前我在实时服务器中运行我的代码时遇到问题,即使我可以在我的本地主机中运行它。

    if($con->connect_error){
    $response['success'] =0;
    $response['message'] ='could not connect to database';
    print(json_encode($response));
    die(print(json_encode($response)));
}

$response['success'] =1;
$response['message'] ='successfully connected to the database';
print(json_encode($response));


$depart = $_GET['depart'];
$destination = $_GET['destination'];
$sql = "INSERT INTO request (dateNtime, depart, destination, status) VALUES (now(),$depart,$destination,0)"; 
$mysql=mysqli_query($con,$sql);

if($mysql)
{
    echo "successfully";
}
else
{
    echo mysqli_error($con);
}

mysqli_close($con);

目前这是我在实时服务器中运行此代码时遇到的错误:

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 '\'users\',0)' at line 1 

我可以知道这个错误的原因是什么吗?

【问题讨论】:

标签: php mysqli localhost


【解决方案1】:

从 php 文档中,您的错误似乎 mysqli_error() 请求连接作为参数,将其更改为 mysqli_error($con) 并且它应该可以工作,从那里您可以看到导致它出错的原因。

【讨论】:

  • 感谢您的评论。正如你所说,我已经编辑了我的问题。现在,如上所述,我遇到了一个不同的错误。为什么这个错误意味着?是否与MySQL版本问题有关?
  • @DHP_07 — 您现在遇到了不同的问题。您应该接受这个答案并提出一个新问题,而不是更改问题,这样这个答案就不再有意义了。
【解决方案2】:

创建查询后,请执行 echo $sql; 并根据您获得的内容更新问题。 可能你会看到你的$destination 是错误的,但我不能确定,因为我不知道你的桌子是什么样的。如果您在 mysql 中运行,还请包括来自 DESC request 的结果。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-04
    • 1970-01-01
    • 2015-01-02
    • 1970-01-01
    • 2019-08-25
    • 2021-06-16
    • 2020-11-06
    相关资源
    最近更新 更多