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

Using system() and bringing back the results
I am aware that you can use system() within PHP to execute system commands, but I was wondering if t

filesize() returns 0
I have a socket program that runs in an infinite loop, listening for connections, in this socket I h

User feedback after MySQL query has been executed
Hi all, I've just registered on PHPFreaks because I've got a question that I simply can't work out b

How to display objects in a row
I have 7 codes that i want to display in a row one next to another.
The first is {$ads->ad

Database/Table Collation
What is the Database, and table collations used for? i don't understand what there used for since co

How to give the privillege for triggers?
Hi,

How to give the privillage for triggers to particular user?

Please let me

This is driving me nuts!
This insert query looks to be alright, however I get this error:

QuoteYou have an error in yo

Secure pages Sessions vs. Cookies & session_destroy() help
Im new here and new to PHP, I hope you can help me with some questions.

Im writing my web ap

Removing Title From database problem
Hi again ! i am having an issue with updating database. When i update any price of a title it remove

Echo-ing MySQL content and Keep Formatting?
I have data in my MySQL such as:

QuoteBlah blah

Blah blah

etc
but when i ech

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