joshluv33 Posted January 7, 2009 Share Posted January 7, 2009 I am attempting to use a Mysql query to update an existing entry in the db, but every time it runs it adds a new entry instead of updating the existing. Here is the code I'm using: <? # this is processed when the form is submitted # back on to this page (POST METHOD) if ($_SERVER['REQUEST_METHOD'] == "POST") { # escape data and set variables $id = addslashes($_POST["id"]); $cat = addslashes($_POST["category"]); $name = addslashes($_POST["name"]); $submitted_by = addslashes($_POST["submitted_by"]); $ing1 = addslashes($_POST["ing1"]); $ing2 = addslashes($_POST["ing2"]); $ing3 = addslashes($_POST["ing3"]); $ing4 = addslashes($_POST["ing4"]); $ing5 = addslashes($_POST["ing5"]); $ing6 = addslashes($_POST["ing6"]); $ing7 = addslashes($_POST["ing7"]); $ing8 = addslashes($_POST["ing8"]); $ing9 = addslashes($_POST["ing9"]); $ing10 = addslashes($_POST["ing10"]); $ing11 = addslashes($_POST["ing11"]); $ing12 = addslashes($_POST["ing12"]); $ing13 = addslashes($_POST["ing13"]); $ing14 = addslashes($_POST["ing14"]); $ing15 = addslashes($_POST["ing15"]); $text = addslashes($_POST["text"]); mysql_select_db($db_name) or die(mysql_error()); $update = "UPDATE recipes SET category='$category', submitted_by='$submitted_by', name='$name', ing1='$ing1', ing2='$ing2', ing3='$ing3', ing4='$ing4', ing5=$ing5, ing6='$ing6', ing7='$ing7', ing8='$ing8', ing9='$ing9', ing10='$ing10', ing11='$ing11', ing12='$ing12', ing13='$ing13, ing14='$ing14', ing15='$ing15', text='$text' WHERE id = '" . $id . "'"; mysql_query($update) or die(mysql_error()); } ?> All I can figure is that I have the WHERE clause messed up, but I have tried... WHERE id ='23' and it still adds a new entry. Any thoughts would be appreciated. Thanks. Quote Link to comment Share on other sites More sharing options...
fenway Posted January 8, 2009 Share Posted January 8, 2009 there's no way that update can ever insert a record (unless there's a trigger). Quote Link to comment Share on other sites More sharing options...
joshluv33 Posted January 8, 2009 Author Share Posted January 8, 2009 Well, I figured out that I forgot to change the form action to direct to this update query...instead I had it going through a similar query that used INSERT. The update page and insert page are identical and I overlooked the action......sometimes the most obvious gets overlooked. Thanks. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted January 8, 2009 Share Posted January 8, 2009 You are missing a single-quote after $ing13 Quote Link to comment 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.