MySQL Error on Text Area Insert

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
richo
Forum Commoner
Posts: 58
Joined: Sun Aug 06, 2006 11:56 am

MySQL Error on Text Area Insert

Post 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
richo
Forum Commoner
Posts: 58
Joined: Sun Aug 06, 2006 11:56 am

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Yep, desc is a keyword meaning descending. It's used in ORDER BY clauses.
richo
Forum Commoner
Posts: 58
Joined: Sun Aug 06, 2006 11:56 am

Post by richo »

aharrr, or course! Thanks Feyd. :D
Post Reply