0

I am not sure why I am getting below error while running query. You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1

This is on centos clodlinux serever Server version: 10.3.18-MariaDB-cll-lve MariaDB Server

$data = mysql_query("SELECT subject, dateline, ticketid, fullname, departmentid, priorityid, firstpostid  FROM `swtickets` WHERE ticketstatusid = 1 AND ticketid > ".$_newticket["lastnewticketid"]." ORDER BY dateline ASC LIMIT 1") or die(mysql_error()); while($temp = mysql_fetch_array( $data )) {
$_newticket = $temp; } 

$data = mysql_query("SELECT contents FROM  `swticketposts` WHERE ticketpostid =". $_newticket["firstpostid"]) or die(mysql_error()); while($temp = mysql_fetch_array( $data )) $_newticket["messagecontents"] = $temp['contents'];}

I have trie to edit $_newticket["firstpostid"."] but still getting same error.

  • 3
    Echo your queries to see what they contain and check for quoting mismatches. Also, mysql_* functions are deprecated as of PHP 5.5.0, and removed as of PHP 7.0.0. Switch your code to use [PDO](https://secure.php.net/manual/en/pdo.prepared-statements.php) or [mysqli](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) instead. Be sure to use prepared statements and parameter binding, so **you'll never have to worry about quoting issues again.** – aynber Oct 17 '19 at 14:03
  • 2
    Possible duplicate of [Why shouldn't I use mysql\_\* functions in PHP?](https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Dharman Oct 18 '19 at 23:30
  • 1
    Use binding, not concatenation. – Rick James Oct 20 '19 at 18:56

1 Answers1

-1

The variable $_newticket["lastnewticketid"] contains an empty string. Therefore your statement looks like SELECT .... FROM table WHERE ID > ORDER BY DATELINE ....

If you had correct error handling in your code, you could have spared yourself the question.

$stmt= "SELECT subject, dateline, ticketid, fullname, departmentid, priorityid, firstpostid  FROM `swtickets` WHERE ticketstatusid = 1 AND ticketid > ".$_newticket["lastnewticketid"]." ORDER BY dateline ASC LIMIT 1";

if (!($data= mysql_query($stmt)))
{
  fwrite(STDERR, "The statement $stmt failed. Error: " . mysql_error());
  exit(1);
}
Georg Richter
  • 5,970
  • 2
  • 9
  • 15
  • I know that the mysql extension is deprecated (and I wrote mysqli 15 years ago), but that was not the question. And if you would replace the mysql api calls with mysqli the problem would be still the same. – Georg Richter Oct 22 '19 at 15:49
  • Not really. With MySQLi you can enable error reporting and you would find this problem much easier. Also with prepared statements, this issue would not happen. – Dharman Oct 22 '19 at 15:50