0

I have an update statement which should update a product using information the user has submitted from a form

The error being that nothing gets updated, the sql code does nothing, and changes nothing in the database
Can anyone see an error in the code?

$user_id = ($_SESSION['user_id']);
	$product_id = ($_POST['product_id']);
	$sql_updateProduct = "UPDATE products SET title = '$_POST[title]', director = '$_POST[director]', cert_id = '$_POST[certificate]', cat_id = '$_POST[category]', format_id = '$_POST[format]', condition_id = '$_POST[condition]', user_id = '$user_id', description = '$_POST[description]', image = '$_POST[image]' WHERE product_id = '$product_id'";
	mysql_query($sql_updateProduct) or die (mysql_error());

		echo"<h1>Record Updated</h1>";

Everything above this section of code works fine, I have narrowed the issue down to this section of code. Any help would be much appreciated.

3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by lit108
0

Have you tested the connection to the database?

$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

0

Are you sure you're wanting to update an existing record? Or are you trying to add a brand new record (in which case you want an 'INSERT INTO' statement rather than an 'UPDATE'). I can't seem to see any immediate errors here... Do you get a mysql error printed to the browser? or do you see the 'Record updated'

0

the connection is fine as there are other queries using the same connection. And yes I am trying to update an existing record, there is a form previous to this is populated with existing product information the user then edits any of the fields they require and then clicks update.
When this process.update.php script runs I see record updated, however there is no change in the product

0

perhaps your form values aren't being passed correctly.
Perform a check to see if they're set first:

if(isset($_SESSION['user_id']))
{
   echo "it's set";
}

Or alternatively simply echo out each of the $_POST values to see if they're all there

0

they are set correctly. I have figured out further that if I take out the WHERE statement out it works, changing all the values in the table. So perhaps its something to do with the product_id = $product_id

I just can't work it out though

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.