newbreed65 Posted November 17, 2008 Share Posted November 17, 2008 Hey Everyone Just making the admin side of my current “project” when I’ve come to a issue inserting and updating data on one of my tables. I’ve spent the last hour looking for what I could be missing but I can’t see what it is, any clues I know it prob something silly. this is the error I’m getting when inserting and it more or less the same with updating 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 'from, dob, bio, modifiedby) VALUES (NULL, 'Morgan', 'Freeman', 'USA', '2005-06-1' at line 1 and heres the php file that has the error in <?php require('../conn.php'); //this code below loops the $_POST Values so $_POST[value] is accessble as $value foreach ($_POST as $key => $value) { $$key = $value; } switch ($action) { //$action decides which case "action" (add,edit delete whatever) via what button was clicked on in the first place case "Create Person": $sql = "INSERT INTO people (person_id, firstname, surname, from, dob, bio, modifiedby) " . "VALUES (NULL, '$firstname', '$surname', '$from', '$dob', '$bio', '$editby')"; $result = mysql_query($sql) or die(mysql_error()); $redirect = 'index.php'; break; case "Delete Person": $sql = "DELETE FROM people " . "WHERE person_id = $pid"; $result = mysql_query($sql) or die(mysql_error()); $sql = "DELETE FROM casts WHERE person_id = $pid"; $result = mysql_query($sql) or die(mysql_error()); $redirect = 'index.php'; break; case "Update Person": $sql = "UPDATE movie " . "SET firstname='$firstname'," . "surname='$surname'," . "from='$from', dob='$dob'," . "bio='$bio', modifiedby='$editby' " . "WHERE person_id = $pid"; $result = mysql_query($sql) or die(mysql_error()); $redirect = 'index.php'; break; } header("Location: $redirect"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/133115-problem-inserting-and-updating/ Share on other sites More sharing options...
premiso Posted November 17, 2008 Share Posted November 17, 2008 $sql = "INSERT INTO people (`person_id`, `firstname`, `surname`, `from`, `dob`, `bio`, `modifiedby`) " . "VALUES (NULL, '$firstname', '$surname', '$from', '$dob', '$bio', '$editby')"; I am sure from is a keyword in mysql, use backticks ( ` ) to define columns to avoid this issue. Quote Link to comment https://forums.phpfreaks.com/topic/133115-problem-inserting-and-updating/#findComment-692270 Share on other sites More sharing options...
PFMaBiSmAd Posted November 17, 2008 Share Posted November 17, 2008 http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html Rename the from column to some other name. Don't use reserved keywords as column or table names. Quote Link to comment https://forums.phpfreaks.com/topic/133115-problem-inserting-and-updating/#findComment-692271 Share on other sites More sharing options...
newbreed65 Posted November 17, 2008 Author Share Posted November 17, 2008 haha knew it was something silly thank you both ill be changing the name of the field and cheers PFMaBiSmAd that link should come in usful for a retard like me :-p Quote Link to comment https://forums.phpfreaks.com/topic/133115-problem-inserting-and-updating/#findComment-692276 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.