0

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 '-100,100' at line 1

Why do I keep getting the above error message?

 $numrows = 0;
 for($x = 0; $x <= $i; $x++) {
    $pp = $pp[$x];
    $query = "SELECT count(*) FROM opent WHERE approve = 'Y' AND pp = '" . $pp . "' ORDER BY id desc"; 
    $result = mysql_query($query) or trigger_error("SQL", E_USER_ERROR); 
    $query_data = mysql_fetch_row($result); 
    $numrows = $query_data[0] + $numrows; 
}
chris85
  • 23,846
  • 7
  • 34
  • 51
aaandy
  • 95
  • 1
  • 8
  • 1
    ***Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php).*** [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jun 23 '17 at 19:46
  • 3
    Show us the query with the variables inserted. – Jay Blanchard Jun 23 '17 at 19:46
  • Not your current issue but you can just do `foreach($pp as $value) {` then use `$value`. – chris85 Jun 23 '17 at 19:48
  • I just learned the mysql is no longer supported. Not an everyday PHP user. I'll try to figure out the new way of doing this. – aaandy Jun 23 '17 at 19:55
  • you are doing something wrong ... doesn't mean MySQL doing it wrong way – Rahul Jun 23 '17 at 19:57
  • So PDO is the better way to do it. Avoid MySQLi? – aaandy Jun 23 '17 at 20:31
  • You have array $pp, and a variable $pp=$pp[$x]. Choose different name for this variable. – Michael Jun 23 '17 at 20:34
  • Can show your raw that means the value in $query ? – Bibhudatta Sahoo Jun 24 '17 at 08:13

0 Answers0