Jump to content

[SOLVED] Mysql update adds a new record?


joshluv33

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/139872-solved-mysql-update-adds-a-new-record/
Share on other sites

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.

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.