Jump to content

Insert Problem


xNTx

Recommended Posts

Hello,I've somewhat recently started to learn PHP/SQL. I've managed to make forms that submit to the database just fine, but with on I'm experiencing the following error: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, version, size, comp, link) VALUES ('a',now(),'b','c','d','i','e','f','g'' at line 1And here's the php code off the page, the error occurs once the submit button is pressed. The connection information (datebase, username, password) have been edited out.

<?PHPsession_start();$con = mysql_connect("[b]my host[/b]","[b]my username[/b]","[b]my password[/b]");if (!$con)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("[b]my database[/b]", $con);if (isset ($_POST[submit])){     $title = htmlspecialchars(strip_tags($_POST['title']));    $thumb = htmlspecialchars(strip_tags($_POST['thumb']));    $screen = htmlspecialchars(strip_tags($_POST['screen']));    $screent = htmlspecialchars(strip_tags($_POST['screent']));    $version = htmlspecialchars(strip_tags($_POST['version']));    $size = htmlspecialchars(strip_tags($_POST['size']));    $comp = htmlspecialchars(strip_tags($_POST['comp']));    $link = htmlspecialchars(strip_tags($_POST['link']));    $desc = $_POST['desc'];    $desc = nl2br($desc);    if (!get_magic_quotes_gpc()) {        $title = addslashes($title);        $thumb = addslashes($thumb);        $screen = addslashes($screen);        $screent = addslashes($screent);        $version = addslashes($version);        $size = addslashes($size);        $comp = addslashes($comp);        $link = addslashes($link);        $desc = addslashes($desc);     }$sql="INSERT INTO Games (title, date, thumb, screen, screent, desc, version, size, comp, link) VALUES ('$title',now(),'$thumb','$screen','$screent','$desc','$version','$size','$comp','$link')";if (!mysql_query($sql,$con))  {  die('Error: ' . mysql_error());  }}if (!isset($_SESSION['user'])){echo "You must log in. </div></div>"; include('footer.php'); echo "</body></html>"; exit;}echo "Hello, NT. You are logged in. You are adding a game.<br /> <br /><form name='gamesubmit' id='gamesubmit' method='post' action=''><table><tr><td class='td' valign='top'><input type='text' name='title' class='forminput' maxlength='25' /> Title<br /><br /><input type='text' name='thumb' class='forminput' maxlength='50' /> Thumbnail<br /> <br /><input type='text' name='screen' class='forminput' maxlength='100' /> Screenshot<br /> <br /><input type='text' name='screent' class='forminput' maxlength='100' /> Screenshot 2<br /> <br /><input type='text' name='version' class='forminput' maxlength='100' /> Version<br /> <br /><input type='text' name='size' class='forminput' maxlength='100' /> Size<br /> <br /><input type='text' name='comp' class='forminput' maxlength='100' /> Compatible<br /> <br /><input type='text' name='link' class='forminput' maxlength='100' /> File Link<br /> <br /><textarea rows='7' cols='30' name='desc' class='forminput'></textarea><br /> <br /></td></tr></table><input type='submit' value='Submit' name='Submit' id='Submit' class='sub_button' /></form>";mysql_close($con);?>

The field names in the database match up to the ones I've typed in the script, if any more information is needed, please say so.I appreciate any and all help or advice,xNTx

Link to comment
Share on other sites

desc is a reserved keyword and needs to be surrounded by backquotes (`):

sql="INSERT INTO Games (title, date, thumb, screen, screent, `desc`, version, size, comp, link) VALUES ('$title',now(),'$thumb','$screen','$screent','$desc','$version','$size','$comp','$link')";

Link to comment
Share on other sites

desc is a reserved keyword and needs to be surrounded by backquotes (`):
sql="INSERT INTO Games (title, date, thumb, screen, screent, `desc`, version, size, comp, link) VALUES ('$title',now(),'$thumb','$screen','$screent','$desc','$version','$size','$comp','$link')";

Thanks! I didn't know about reserved keywords. Will learn more about them to avoid the same mistake.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...