开发者

MYSQL Query works direct but not via PHP!

I have the following error pop up on the PHP page. This is the result of echoing out $flightquery just before the query takes place.

INSERT INTO Flights (`adshex`,`flightno`,`route`) VALUES ('01002F','MSR845','HECA-DAAG') WHERE NOT EXISTS (SELECT flightno FROM Flights WHERE `flightno` = 'MSR845' AND `adshex` = '01002F' AND TIMESTAMPDIFF(MINUTE,`timestamp`,CURRENT_TIMESTAMP) > 开发者_StackOverflow360);

Error: 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 'WHERE NOT EXISTS (SELECT flightno FROM Flights WHERE `flightno` = 'MSR845' AND `' at line 1

If I copy the insert statement into the MYSQL server it works with no errors but through a PHP it breaks!

  $flightquery = "INSERT INTO Flights (`adshex`,`flightno`,`route`) VALUES ('$adshex','$flightno','$route') WHERE NOT EXISTS (SELECT flightno FROM Flights WHERE `flightno` = '$flightno' AND `adshex` = '$adshex' AND TIMESTAMPDIFF(MINUTE,`timestamp`,CURRENT_TIMESTAMP) > 360);";

UPDATE:

I changed it to errno and it is 1064 which is reserved keywords, where am I doing that? timestamp?


From the MySQL syntax for INSERT there can be no WHERE clause with INSERT.


got the bad boy remove ; after 360),


The query doesn't work in MySQL Server because there are PHP variables.

$adshex, $flightno, $route

"INSERT INTO Flights (`adshex`,`flightno`,`route`) 
VALUES ('$adshex','$flightno','$route') 
WHERE NOT EXISTS (SELECT flightno FROM Flights 
    WHERE `flightno` = '$flightno' AND `adshex` = '$**adshex**' 
    AND TIMESTAMPDIFF(MINUTE,`timestamp`,CURRENT_TIMESTAMP) > 360);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜