Jump to content

SQL Error in Syntax


stublackett

Recommended Posts

Hi Guys,

 

I'm getting this error :

 

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

 

I assume that my Database is setup not to allow apostrophes

 

The current Collation is set to : latin1_swedish_ci

Link to comment
Share on other sites

My Code for SQL Insert is :

 

// If all is ok, Insert into DB
	$sql = "INSERT INTO $db_table(title,location,day,month,year,description) values ('$title','$location','$day','$month','$year','$description')"; 
	// Incase needed($result = mysql_query($sql ,$db));
	($result = mysql_query($sql ,$db) or die(mysql_error()));

 

The main problem area seems to be the description box which is getting a fair bit of information

 

The PHP Bit for that is

 

Is it worth trying stripslashes ?

 

<?php
if (!empty($_POST['description'])) {
	$description = $_POST['description'];
}else{
	$description = NULL;
	$errors['description'] = '<p><font color="red">You need to enter a description for your event</font></p>';
}
?>

Link to comment
Share on other sites

You need to use the mysql_real_escape_string() function on any data in a query that could contain special characters. This does two things, it prevents sql injection in external data and it prevents special characters in the data from breaking the query and causing a sql syntax error.

Link to comment
Share on other sites

My code now looks like this :

 

$sql = "INSERT INTO $db_table2(title, category, address, postcode, telephone, email, website, info, image1, image2) values ('$title','$category','$address','$postcode','$telephone','$email','$website','$info','$img1','$img2')";
mysql_real_escape_string($info) 

 

But its still complaining when an ' or another foreign character is entered, Are we sure that its not down to the Databases' Collation?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.