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

updating a single value to multiple non consecutive rows
I need to update the same value to multiple non consecutive rows. I need to add an experation date t

Kill a process
I have a question - how can I kill a process from a command line or by using Oracle SQL Developer? I

remove a ; from emails in textarea
Code: <?php

session_start();

$database_host = "localhost&qu

How do I create a 2D game "camera" to follow player?
In J2ME programming I'm targeting MIDP 2.0 devices.

I'm using gamecanvas and I was thinking t

onclick problem
I have <input type="text" name="message">
<a href=page2.

need help about
i store the value of my select statement result to an array and stored it to a variable named $fname

Check something, wait, check again, do something!
Hi guys.

I wonder if someone can help me with this.

Basically, what I want to do is (

Email to a friend script problems
I have this send-to-a-friend script with 2 issues:


1) When you open the form popup on a p

writing a screen scraper
Hello,

I'm writing a screen scraper application and want to be able to get absolute addresses

listing help
Hi,

at first, great new design!!! I like it,

i got a problem,

I want to list so

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