March 5, 2012
Difficulties with storing links in a mysql database?
Question by Matt Williams
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! 😀
Thanks Everyone
Answer by Starx
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')";