mysql query with single quotes in a variable


Posted on 16th Feb 2014 07:03 pm by admin

$sitedetails = "INSERT INTO vars (address, sitename, description, ownername, theme) VALUES ('$url', '$sitename', '$description', '$ownername', '$theme') ";
mysql_query($sitedetails) or die(mysql_error()); // site details in mysql

If say $sitename = "scott nicol's blog"; - this will give me:
Code: 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 's blog test', 'scott nicol', 'scott nicol', 'default')' at line 1
I know it's due to the single quite in 'nicol's', how do I keep the quote, but stop this error?

No comments posted yet

Your Answer:

Login to answer
84 Like 52 Dislike
Previous forums Next forums
Other forums

DOMDocument
Hello All,

I need to take an XML document, modify some of the nodes in it and then perform a

PHP File Upload Problem
Hi, I have written a very simple file upload script but it fails for reasons I can't explain. Hope

Remove letter from numeric textbox
I have a textbox that will search the employee database by entering in the employee ID and it will r

Code Help.. If txt input box empty search X instead..
I am having a problem with my search script. At current it will simply search by a selected date whi

problem with sql querry in php script
Hello guys,

What I want to do is I want to read out a csv file and then but te conent ot the

Need Successful Return
Hello I am currently working a form here, and I have everything figured out except when I click the

Locking mysql tables with php
Hi

BACKGROUND:
I have multiple instances of the same php script running in a WAMP environ

Querying info from one table based on info in another
Hi, I am currently trying to make a part for my user driven website where one user can subscribe to

Error Messaging not working
I changed the way my form tells the user of an error. But I can't seem to get it to work properly.

PHP Form to Variable.
Hi! I have written a HTML-form code in DreamWeaver CS3 (in a PHP doc) and I really need it to work s

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash