PHP代码中的解析错误(意外的T_VARIABLE)

时间:2013-09-12 15:38:36

标签: php

我正在尝试运行以下代码:

if ($result = $mysqli->query($query)) {

    /* fetch object array */
    while ($row = $result->fetch_row()) {
        $query = "INSERT INTO Table2 SELECT s.* FROM Table1 s WHERE id=" . $row[1] . ";"
        $mysqli->query($query);
        $query = "DELETE FROM Table1 WHERE id=" . $row[1] . ";"
        $mysqli->query($query);
    }

    /* free result set */
    $result->close();
}

但它正在回归:

$mysqli->query($query);

任何人都知道它可能是什么?

  

解析错误:语法错误,意外T_VARIABLE ......

3 个答案:

答案 0 :(得分:6)

在每一行的末尾添加;

$query = "INSERT INTO Table2 SELECT s.* FROM Table1 s WHERE id=" . $row[1] . ";";
                                                                                ^
$query = "DELETE FROM Table1 WHERE id=" . $row[1] . ";";
                                                       ^

答案 1 :(得分:2)

好像你的查询有问题

$query = "INSERT INTO Table2 SELECT s.* FROM Table1 s WHERE id=" . $row[1] . ";"

我认为应该是

$query = "INSERT INTO Table2 SELECT s.* FROM Table1 s WHERE id=" . $row[1];

答案 2 :(得分:1)

他是对的,你在这一行上错过了一个分号:

$query = "INSERT INTO Table2 SELECT s.* FROM Table1 s WHERE id=" . $row[1] . ";"