语法错误意外'FROM'(T_STRING)

时间:2018-01-20 11:00:13

标签: php mysql syntax

我是PHP和MySQL的初学者,不知道出了什么问题。它在第8行说错误

syntax error unexpected 'FROM' (T_STRING)

以下是代码:

<?php
require "conn.php";

$category = $_POST["category"];
$fruit = $_POST["fruit"];
$cost = $_POST["cost"];

DELETE FROM `Temptable` WHERE image_path = "";
UPDATE Temptable SET (`category`, `fruit`, `cost`) VALUES ('$category','$fruit','$cost');
$mysql_qry = "INSERT INTO Datatable (`category`, `fruit`, `cost`) SELECT `categrory`, `fruit`, `cost` FROM `Temptable` WHERE `id` >= '1'";

if($Datatable->query($mysql_qry) === true) {
	echo "Successful";
}
else {
	echo "Error: " . $mysql_qry . "<br>" . $Datatable->error;
}
$Datatable->close();
$Temptable->close();
?>

2 个答案:

答案 0 :(得分:1)

生成错误只是因为您已将mysql查询直接放入PHP无法理解的PHP代码中。您应该将DocumentDELETE语句作为字符串变量放置,就像您对UPDATE语句所做的那样

INSERT

答案 1 :(得分:0)

deleteupdate语句需要被注释掉或作为变量正确创建 - 由于这些字符串而出现错误

<?php
    require "conn.php";

    $category = $_POST["category"];
    $fruit = $_POST["fruit"];
    $cost = $_POST["cost"];

    #DELETE FROM `Temptable` WHERE image_path = "";
    #UPDATE Temptable SET (`category`, `fruit`, `cost`) VALUES ('$category','$fruit','$cost');
    $mysql_qry = "INSERT INTO Datatable (`category`, `fruit`, `cost`) SELECT `categrory`, `fruit`, `cost` FROM `Temptable` WHERE `id` >= '1'";

    if($Datatable->query($mysql_qry) === true) {
        echo "Successful";
    }
    else {
        echo "Error: " . $mysql_qry . "<br>" . $Datatable->error;
    }
    $Datatable->close();
    $Temptable->close();
?>