RopeADope Posted May 15, 2010 Share Posted May 15, 2010 I have some php code that's supposed to execute a mysql statement to update an already existing record. I can't figure out why it doesn't update. Here's the bit of code. The Form: echo "<form method=\"post\" action=\"edit2.php\" enctype=\"multipart/form-data\"> <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"100000\"> <input type=\"hidden\" name=\"id\" value\"$id\"> <tr><td>Image</td><td></td><td><img src=\"$dir\" width=\"50\" height=\"50\"></td></tr> <tr><td>Upload New Image</td><td></td><td><input type=\"file\" name=\"file\" id=\"file\"></td></tr> <tr><td>Type</td><td></td><td><input type=\"text\" name=\"type\" value=\"$type\"></td></tr> <tr><td>Name</td><td></td><td><input type=\"text\" name=\"product_name\" value=\"$product_name\"></td></tr> <tr><td>Price</td><td>\$</td><td><input type=\"text\" name=\"price\" value=\"$price\"></td></tr> <tr><td>Description</td><td></td><td><input type=\"text\" name=\"description\" value=\"$description\"></td></tr> <tr><td colspan=\"3\"><center><input type=\"submit\" value=\"Submit\"></td></tr></form>"; The update: <?php include('./inc/session.php'); $id=$_POST['id']; $type=$_POST['type']; $product_name=$_POST['product_name']; $price=$_POST['price']; $description=$_POST['description']; include('./inc/connect.php'); $sql="UPDATE products SET type='$type', product_name='$product_name', price='$price', description='$description' WHERE id='$id'"; $result=mysql_query($sql)or die(mysql_error()); mysql_close(); echo "Updated"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/201889-update-multiple-fields-in-mysql/ Share on other sites More sharing options...
TeddyKiller Posted May 15, 2010 Share Posted May 15, 2010 Do you recieve an mysql_error? If so, what error is it. You might also want to consider using mysql_real_escape_string for all values going into the query. Quote Link to comment https://forums.phpfreaks.com/topic/201889-update-multiple-fields-in-mysql/#findComment-1058860 Share on other sites More sharing options...
RopeADope Posted May 16, 2010 Author Share Posted May 16, 2010 Do you recieve an mysql_error? If so, what error is it. You might also want to consider using mysql_real_escape_string for all values going into the query. I don't get any errors, nothing gets updated though. I'll check out the mysql_real_escape_string and see if that fixes anything. In the mean time, any other help would be great. Quote Link to comment https://forums.phpfreaks.com/topic/201889-update-multiple-fields-in-mysql/#findComment-1058956 Share on other sites More sharing options...
jagdish kothapalle Posted May 19, 2010 Share Posted May 19, 2010 Hi, If there is no mysql error and nothing is getting updated, then the where condition is not getting satisfied. It ought to be either of the two. Quote Link to comment https://forums.phpfreaks.com/topic/201889-update-multiple-fields-in-mysql/#findComment-1060559 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.