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:
Did you know?Explore Trending and Topic pages for more stories like this.
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

LOOPing Problem
Hello All!

The following code loops through the data and displays the data accordingly. My p

User registration and login
I don't know whether this is the correct forum, if not i apologise but am pretty desperate at the mo

couldn't connect to your database
Hello I am new to php mysql

Actually i have read A tutorial on nettuts
"http://net.tu

Confusing Functions
So, I've been reading up on Functions and I like them! However, I need some help using variables in

array ...
hi
Code: function formatCategories($categories, $parentId)
{
// $navCat stores all child

Problems with adding a link to one position in a 'foreach' loop, please help
Hello!

Iam pretty new to programming and I wanna create a table with users from an array. It

PHP page loading in Firefox but not in IE
hello,

i am currently doing a project in PHP and i have a problem. If I view the project in M

Weird MySQL error, why am I recieving this?
PHP Code:


<?php require "global_settings.php"; ?>
<titl

ImageCreate()
When I create an image and add text to it I want my text to be replaced with a PNG image, because th

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

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