Page 1 of 1

MySQL Error on Text Area Insert

Posted: Thu Aug 24, 2006 3:34 pm
by richo
Hi, I get 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 'desc='Description goes here.', shortdesc='Designed and developed CSS/XHTML or Em' at line 1
Using this script:

Code: Select all

$errors = array(); 
$slideadded = false;

if (isset($_POST['submitslide'])) {

	$title = $_POST['title'];
	$img = $_POST['img']; 
	$snapimg = $_POST['snapimg'];
	$desc = $_POST['desc'];
	$shortdesc = $_POST['shortdesc'];
	
	if ($title == ''){
		$errors[] = 'Please enter the venue of the gigtitle. ';
	}
	if ($img == ''){
		$errors[] = 'Please enter an image. ';
	}
	if ($snapimg == ''){
		$errors[] = 'Please enter a snapshot image. ';
	}
	if ($desc == ''){
		$errors[] = 'Please enter a description. ';
	}
	if ($shortdesc == ''){
		$errors[] = 'Please enter a short description. ';
	}
	if (strlen($shortdesc) >= 310){
		$errors[] = 'Your short description is too long. ';
	}
	
	if (! $errors){
		$sql = 	"INSERT INTO slides SET " .
				"title='$title', " .
				"img='$img', " .
				"snapimg='$snapimg', " .
				"desc='$desc', " .
				"shortdesc='$shortdesc'";
	}
	if (mysql_query($sql)) {
		$slideadded = '<p><b>Slide successfully added.</b></p>';
	} else {
		echo("<p>Error updating: " . mysql_error() . "</p>");
	}
	
}


?>

<?php echo "<b>". implode($errors) . "</b>" ?>
<?php echo $slideadded ?>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
	<p>Slide title:</p>
	<input type="text" name="title"></input>
	<p>Image location:</p>
	<input type="text" name="img"></input>
	<p>Snapshot image location:</p>
	<input type="text" name="snapimg"></input>
	<p>Description:</p>
	<textarea name="desc" rows="7" cols="35"></textarea>
	<p>Short Description:</p>
	<textarea name="shortdesc" rows="7" cols="35"></textarea>
	<p><input type="submit" name="submitslide" value="submit"></p>
</form>
Any ideas would be much appreciated. I don't understand, i've used a similar script before and had no problems. Also when i take out the erroring inserts, i puts everything else in fine!

8O

Posted: Thu Aug 24, 2006 3:46 pm
by richo
To save people's time i think i worked out what it was.

I think atleast 'desc' is maybe a pre-defined name or function in MySQL as when i changed it to a new unique name it works fine.

Posted: Thu Aug 24, 2006 4:15 pm
by feyd
Yep, desc is a keyword meaning descending. It's used in ORDER BY clauses.

Posted: Fri Aug 25, 2006 6:40 am
by richo
aharrr, or course! Thanks Feyd. :D