-1

Im trying to store some links in a database but i think my SQL code is off but i cant figure out what the problem is.

INSERT INTO `users`(`fbid`, `meme`) VALUES (122321414, http://google.com)

I think its the : character but im not sure how to escape it in SQL

If you could post anything to help me then thanks a lot! :D

Thanks Everyone

Matt Williams
  • 79
  • 1
  • 8
  • 2
    Put it in quotes. `'http://google.com'` – Pekka Mar 05 '12 at 16:54
  • Possible duplication of http://stackoverflow.com/questions/2122866/how-to-insert-special-character-in-mysql-via-php-and-display-on-html-page – Milap Mar 05 '12 at 16:56

5 Answers5

3

The string value of the URL has to be in quotes.

INSERT INTO `users`(`fbid`, `meme`) VALUES (122321414, 'http://google.com')
Joe Stefanelli
  • 132,803
  • 19
  • 237
  • 235
3

Enclose the link in single quotes. String values must always be quote-enclosed in SQL statements.

INSERT INTO `users`(`fbid`, `meme`) VALUES (122321414, 'http://google.com')
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
2

You are not putting the values in quotes

Strings need to be in quotes and number can be in quotes if you want to store as a string

Should be

INSERT INTO users(fbid, meme) VALUES (122321414, 'http://google.com')
bretterer
  • 5,693
  • 5
  • 32
  • 53
0

You should escape the values, when entered into the database.

Use mysql_real_escape_String() to escape such values and never forget to enclose the values with a single-quote('), keeps you safe most of the time.

$url = mysql_real_escape_string("http://google.com");
$query = "INSERT INTO `users`(`fbid`, `meme`) VALUES (122321414, '$url')";
Starx
  • 77,474
  • 47
  • 185
  • 261
0

If you're having issues with this in the future, make use of mysql_real_escape_string().

$query = "INSERT INTO `users`(`fbid`, `meme`) VALUES ('122321414', " . mysql_real_escape_string('http://google.com') . ")";
Harti
  • 1,480
  • 12
  • 16