2

i have a problem , each time i try to do select and fetch this error show

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

  <?php
      mysql_connect("localhost", "root", "123") or die() ; 
 mysql_select_db("boom") or die() ; 
 //Retrieves data from MySQL 
 $select= "select * from add" ;
 $data = mysql_query($select) or die(); 
 //Puts it into an array 
 while($info = mysql_fetch_array( $data )) 
 { 

 echo "<img src=images/".$info['photo'] .">";
 }
 //Outputs the image and other data
 ?>

what is the problem here ?

Nikoloff
  • 4,050
  • 1
  • 17
  • 19
Bader H Al Rayyes
  • 514
  • 2
  • 7
  • 24

4 Answers4

4

add is a reserved word:

http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Rewrite the query like so:

$select= "select * from `add`" ; 
Johan
  • 74,508
  • 24
  • 191
  • 319
3
$select = "select * from `add` ;

Adding the backticks will solve your problem. ADD is a reserved word in MySQL

jprofitt
  • 10,874
  • 4
  • 36
  • 46
Ignacio
  • 5,300
  • 1
  • 15
  • 10
2

Ensure that 'add' is the table name (add is a reserved word), and try escaping your table name with the ` character.

Backticks are good practise to escape the table name for MySQL (Next to the 1 on your keyboard).

SELECT * FROM `add`
Darbio
  • 11,286
  • 12
  • 60
  • 100
1

"Add" is a reserved word in MySQL. You can either change the name of your table, or escape it out. According to this it looks like you would need to put backticks around the table name, like add.

mandreko
  • 1,766
  • 2
  • 12
  • 24