I made a little code to update record in database like this:

require_once('includes/config.php');

if ((isset($_POST["DO_update"])) && ($_POST["DO_update"] == "edit_product")) {

	$ProductID = $_POST["txtProductID"];
	$CategoryID = $_POST["txtCategoryID"];
	$ProductName = $_POST["txtProductName"];
	$ProductPrice = $_POST["txtProductPrice"];
	$IsRebate = $_POST["selIsRebate"];
	$RebatePrice = $_POST["txtRebatePrice"];
	$ImageFileName = $_POST["txtImageFileName"];
	$BigImageFileName = $_POST["txtBigImageFileName"];
	$ProductDetails = $_POST["txtProductDetails"];

	$query_update  = "UPDATE ks_products SET `prod_name` = '$ProductName'";
	$query_update .= ", `prod_price` = '$ProductPrice'";
	$query_update .= ", `prod_is_rebate` = '$IsRebate'";
	$query_update .= ", `prod_rebate_price` = '$RebatePrice'";
	$query_update .= ", `prod_image` = '$ImageFileName'";
	$query_update .= ", `prod_big_image` = '$BigImageFileName'";
	$query_update .= ", `prod_details` = '$ProductDetails'";
	$query_update .= ", `cat_id` = '$CategoryID'";
	$query_update .= "WHERE `prod_id` = '$ProductID' LIMIT 1";

	mysql_select_db($database_index, $index);
	mysql_query($query_update, $index) or die(mysql_error());

}

No error found but the record cannot be updated, plz help me!
Only prod_price, prod_is_rebate and prod_rebate_price column is mediumint, others is varchar.

PHP version 5.0.4, MySQL version 4.1

Remove the ' ' quote from your script will do

$query_update  = "UPDATE ks_products SET 
	prod_name = '$ProductName',
	prod_price = '$ProductPrice',
	prod_is_rebate = '$IsRebate',
	prod_rebate_price = '$RebatePrice',
	prod_image = '$ImageFileName',
	prod_big_image = '$BigImageFileName',
	prod_details = '$ProductDetails',
	cat_id = '$CategoryID'
  WHERE prod_id = '$ProductID' LIMIT 1";

Thanks for your help but it didn't work :cry:

I found the bug and fixed it. Thanks for your help :cheesy:

What error message you get?
Make sure you connect to the database properly.
Make sure your database got the variables you use.

You may want to add echo $ProductDetails; after
$ProductDetails = $_POST["txtProductDetails"];
to see if the POST is actually working.

What error message you get?
Make sure you connect to the database properly.
Make sure your database got the variables you use.

You may want to add echo $ProductDetails; after
$ProductDetails = $_POST["txtProductDetails"];
to see if the POST is actually working.

Yes, you are right. I found that the $_POST didn't get value from submit form.

Thanks for your advice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.