2

i am facing problem in inserting image inside db, error message is:

Invalid query: 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 'VALUES('','$_59.jpg','����' at line 1

Query written is:

$insert=mysql_query("INSERT INTO store VALUES(id,name,image)VALUES('','$image_name','$image')") or die("Invalid query: " . mysql_error());

I am Using xamppv3.2.1, Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3, Server version: 5.6.21 - MySQL Community Server (GPL).

John Conde
  • 217,595
  • 99
  • 455
  • 496
Azra Mahrukh
  • 151
  • 1
  • 14
  • 3
    Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Apr 21 '15 at 19:46

2 Answers2

4

You have an errant VALUES keyword:

$insert=mysql_query("INSERT INTO store (id,name,image) VALUES ('','$image_name','$image')") or die("Invalid query: " . mysql_error());

FYI, if your id column is set to auto-increment you don't need to have it in your query:

$insert=mysql_query("INSERT INTO store (name,image) VALUES ('$image_name','$image')") or die("Invalid query: " . mysql_error());

Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
John Conde
  • 217,595
  • 99
  • 455
  • 496
2

Modify your query, you are using VALUES keyword incorrectly. Modify it to:

INSERT INTO store (id,name,image) VALUES('','$image_name','$image')

I doubt your id is VARCHAR type. If it is INT type, put some integer value there.

INSERT INTO store (id,name,image) VALUES(1,'$image_name','$image')

If your id is auto increment, let db insert it

INSERT INTO store (name,image) VALUES('$image_name','$image')
cosmos
  • 2,263
  • 1
  • 17
  • 30
  • id is primary key its on auto increment and ofcors int. i tried doing it like "INSERT INTO store (name,image) VALUES('$image_name','$image')" no luck – Azra Mahrukh Apr 21 '15 at 19:57