0
$sql="SELECT * FROM 'image_upload' where uid='$uid' ";

I have written this query and it is showing me 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 ''image_upload' where uid=''' at line 1

Can you please rectify it..

Shamim Hafiz - MSFT
  • 20,466
  • 38
  • 110
  • 169
user799100
  • 133
  • 2
  • 16

8 Answers8

9

This will work:

$sql = "SELECT * FROM `image_upload` where uid='$uid' ";
Tim Cooper
  • 151,519
  • 37
  • 317
  • 271
Manish Das
  • 3,565
  • 2
  • 20
  • 34
  • yes, my uid is not char or varchar, it is bigint and when i put the query as suggested by you, it shows me uid 0 in my database – user799100 Jun 16 '11 at 07:24
  • 2
    are you sure that $uid store the number you want??? or may be the previous insertions into uid column have size less than the length of your number. – Manish Das Jun 16 '11 at 07:54
4

Use backticks for table names:

SELECT * FROM `image_upload` ...
Pekka
  • 431,103
  • 135
  • 960
  • 1,075
1

You should be using backticks (`) rather than single quotes ('). In fact, you shouldn't be using either in this case since it's not required:

$sql = "SELECT * FROM image_upload where uid='$uid'";

The backticks are only required if your table name has funny characters in it that would otherwise annoy the SQL parser (like a space for example).

And make sure that your uid column is a textual one (like char or varchar) - otherwise you should not be surrounding $uid with the single quotes.

paxdiablo
  • 814,905
  • 225
  • 1,535
  • 1,899
0

$sql="SELECT * FROM image_upload where uid='$uid' ";

gmhk
  • 15,093
  • 27
  • 86
  • 109
0

Can you remove the single quotes, and try again?

SELECT * FROM image_upload where uid='$uid'
Liangliang Zheng
  • 1,713
  • 11
  • 16
0

try this:

$sql="SELECT * FROM image_upload where uid='".$uid."'";
Sujit Agarwal
  • 11,994
  • 11
  • 45
  • 78
0
$sql="SELECT * FROM `image_upload` where uid='$uid' ";

You've been rectified ;)

You need to protect against SQL injections. Please see this thread.

Community
  • 1
  • 1
Znarkus
  • 22,406
  • 22
  • 77
  • 108
-1

Remove single quotes in image_upload Before Query echo $uid; then u ll know the answer

K6t
  • 1,791
  • 1
  • 12
  • 21