准备好的语句出现语法错误 mysql/php

syntax error with prepared statements mysql/php

从昨晚开始就一直在胡思乱想,但无济于事。

createOrder($website,(int)$nVotes,(int)$timeframe,$loggedInUser->email,$server,(int)$start,$referer);

var_dumping 这些变量显示(较早):

string(2) "web1" string(2) "10" string(2) "10" string(23) "myemail@gmail.com" string(8) "myserver" int(1423063633) string(17) "http://google.com"

而似乎有问题的功能是:

function createOrder($website,$votes,$timeframe,$user,$server,$start,$referer)
{
    global $mysqli,$db_table_prefix;
    $time = time();
    $stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."orders (
        serverId,
        orderUser,
        targetUrl,
        nVotes,
        timeframe,
        referer,
        starting
        )
        VALUES (
        ?,
        ?,
        ?,
        ?,
        ?,
        ?,
        ?
        )");
    file_put_contents("error.log", $mysqli->errno . $mysqli->error );
    $stmt->bind_param("sssiisi", $server, $user, $website, $votes, $timeframe, $referer, $start);
    file_put_contents("error1.log", $stmt->errno . $stmt->error );
    $stmt->execute();
    file_put_contents("error1.log", $stmt->errno . $stmt->error );
    $stmt->close(); 

nginx.error.log 归咎于 bind_param

"PHP message: PHP Fatal error: Call to a member function bind_param() on a non-object in funcs.php on line 1223

error.log归咎于语法错误

(check the manual) for the syntax to use near 'starting

  )
                VALUES (
                ?,
                ?,
                ?,
                ?,
                ?,
                ?,
                ?
                )' at line 8

问题是 startingreserved word in MySQL,而您将其用作字段名称。你应该用反引号把它包起来:

    serverId,
    orderUser,
    targetUrl,
    nVotes,
    timeframe,
    referer,
    `starting`