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')";

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!