Mundo Posted March 17, 2009 Share Posted March 17, 2009 mysql_query("UPDATE customer SET customer_firstname = `$_POST[customerupdate_firstname]`, customer_lastname = `$_POST[customerupdate_lastname]`, customer_address1 = `$_POST[customerupdate_address1]`, customer_address2 = `$_POST[customerupdate_address2]`, customer_postcode = `$_POST[customerupdate_postcode]`, customer_dob = `$_POST[customer_dob]`, customer_email = `$_POST[customerupdate_email]`, customer_tel = `$_POST[customerupdate_tel]` WHERE customer_id = `$_POST[customerupdate_id]`"); Whats wrong with that? Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/ Share on other sites More sharing options...
premiso Posted March 17, 2009 Share Posted March 17, 2009 You are using backticks (`) around values. You need to use single quotes (') around them. Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786870 Share on other sites More sharing options...
Mundo Posted March 17, 2009 Author Share Posted March 17, 2009 Now I have the following and it's still not working: mysql_query("UPDATE customer SET customer_firstname = '$_POST[customerupdate_firstname]', customer_lastname = '$_POST[customerupdate_lastname]', customer_address1 = '$_POST[customerupdate_address1]', customer_address2 = '$_POST[customerupdate_address2]', customer_postcode = '$_POST[customerupdate_postcode]', customer_dob = '$_POST[customer_dob]', customer_email = '$_POST[customerupdate_email]', customer_tel = '$_POST[customerupdate_tel]' WHERE customer_id = '$_POST[customerupdate_id]'"); Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786879 Share on other sites More sharing options...
kickstart Posted March 17, 2009 Share Posted March 17, 2009 Hi Nothing obvious except possibly the date of birth being a timestamp or customer_id being a numeric field, but not a good idea to use unsanitised $_POST input. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786887 Share on other sites More sharing options...
ngreenwood6 Posted March 17, 2009 Share Posted March 17, 2009 You need to have a container("", or '') around the $_POST value: mysql_query("UPDATE customer SET customer_firstname = '$_POST["customerupdate_firstname"]', customer_lastname = '$_POST["customerupdate_lastname"]', customer_address1 = '$_POST["customerupdate_address1"]', customer_address2 = '$_POST["customerupdate_address2"]', customer_postcode = '$_POST["customerupdate_postcode"]', customer_dob = '$_POST["customer_dob"]', customer_email = '$_POST["customerupdate_email"]', customer_tel = '$_POST["customerupdate_tel"]' WHERE customer_id = '$_POST["customerupdate_id"]'"); Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786888 Share on other sites More sharing options...
rhodesa Posted March 17, 2009 Share Posted March 17, 2009 add some debugging...MySQL will tell you the problem: mysql_query("UPDATE customer SET customer_firstname = '$_POST[customerupdate_firstname]', customer_lastname = '$_POST[customerupdate_lastname]', customer_address1 = '$_POST[customerupdate_address1]', customer_address2 = '$_POST[customerupdate_address2]', customer_postcode = '$_POST[customerupdate_postcode]', customer_dob = '$_POST[customer_dob]', customer_email = '$_POST[customerupdate_email]', customer_tel = '$_POST[customerupdate_tel]' WHERE customer_id = '$_POST[customerupdate_id]'") or die(mysql_error()); p.s. - whenever you are debugging a MySQL problem....step 1 is to make sure you echo out mysql_error(). if that isn't helpful, echo out the generated SQL and make sure all the values are inserting as you are expecting them to. Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786892 Share on other sites More sharing options...
Mundo Posted March 17, 2009 Author Share Posted March 17, 2009 Maybe it'll help if I post my form: <br /> <form name="updatecustomer" method="POST" action="customer.php?module=update"> <input type="hidden" name="module" value="update" /> Customer ID: <br /> <input type="text" name="customerupdate_id" id="customerupdate_firstname" disabled="disabled" value="<? echo $row['customer_id']; ?>"> <br /><br /> First Name: <br /> <input type="text" name="customerupdate_firstname" id="customerupdate_firstname" value="<? echo $row['customer_firstname']; ?>"> <br /><br /> Surname: <br /> <input type="text" name="customerupdate_surname" id="customerupdate_surname" value="<? echo $row['customer_lastname']; ?>"> <br /><br /> Address Line 1: <br /> <input type="text" name="customerupdate_address1" id="customerupdate_address1" value="<? echo $row['customer_address1']; ?>"> <br /><br /> Address Line 2: <br /> <input type="text" name="customerupdate_address2" id="customerupdate_address2" value="<? echo $row['customer_address2']; ?>"> <br /><br /> Postcode: <br /> <input type="text" name="customerupdate_postcode" id="customerupdate_postcode" value="<? echo $row['customer_postcode']; ?>"> <br /><br /> Date of Birth <b>(YYYY-MM-DD)</b>: <br /> <input type="text" name="customerupdate_dob" id="customerupdate_dob" value="<? echo $row['customer_dob']; ?>"> <br /><br /> E-mail: <br /> <input type="text" name="customerupdate_email" id="customerupdate_email" value="<? echo $row['customer_email']; ?>"> <br /><br /> Telephone: <br /> <input type="text" name="customerupdate_tel" id="customerupdate_tel" value="<? echo $row['customer_tel']; ?>"> <input name="submitcustomerupdate" type="submit" value="submit"> </form> and if($_GET[module] == "update" || isset($_GET['submitcustomerupdate'])) { mysql_query("UPDATE customer SET customer_firstname = '$_POST[customerupdate_firstname]', customer_lastname = '$_POST[customerupdate_lastname]', customer_address1 = '$_POST[customerupdate_address1]', customer_address2 = '$_POST[customerupdate_address2]', customer_postcode = '$_POST[customerupdate_postcode]', customer_dob = '$_POST[customer_dob]', customer_email = '$_POST[customerupdate_email]', customer_tel = '$_POST[customerupdate_tel]' WHERE customer_id = '$_POST[customerupdate_id]'") or die(mysql_error()); } Which gives me: http://i43.tinypic.com/20axus2.jpg Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786900 Share on other sites More sharing options...
kickstart Posted March 17, 2009 Share Posted March 17, 2009 Hi You are mixing $_GET and $_POST. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786904 Share on other sites More sharing options...
ngreenwood6 Posted March 17, 2009 Share Posted March 17, 2009 Did you miss my post? Also kickstart is correct, you need to use either $_GET or $_POST. Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786906 Share on other sites More sharing options...
Mundo Posted March 17, 2009 Author Share Posted March 17, 2009 Hi You are mixing $_GET and $_POST. All the best Keith Ah, that is one mistake I didn't notice, I've changed it, but it's still not working... Did you miss my post? Also kickstart is correct, you need to use either $_GET or $_POST. Sorry, I did miss it! But the code you have posted will not work, I can tell just by looking.I already have quatation marks around the entire query, so it will assume it is the end as soon as it comes across the next lot... Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786916 Share on other sites More sharing options...
rhodesa Posted March 17, 2009 Share Posted March 17, 2009 you can mix GET and POST...your use of them is fine is it producing an error or just not running the update? if there is an error, what is it? try this: if($_GET['module'] == "update" || isset($_POST['submitcustomerupdate'])) { $sql = printf("UPDATE customer SET customer_firstname = '%s', customer_lastname = '%s', customer_address1 = '%s', customer_address2 = '%s', customer_postcode = '%s', customer_dob = '%s', customer_email = '%s', customer_tel = '%s' WHERE customer_id = '%s'", mysql_real_escape_string($_POST['customerupdate_firstname']), mysql_real_escape_string($_POST['customerupdate_lastname']), mysql_real_escape_string($_POST['customerupdate_address1']), mysql_real_escape_string($_POST['customerupdate_address2']), mysql_real_escape_string($_POST['customerupdate_postcode']), mysql_real_escape_string($_POST['customer_dob']), mysql_real_escape_string($_POST['customerupdate_email']), mysql_real_escape_string($_POST['customerupdate_tel']), mysql_real_escape_string($_POST['customerupdate_id']) ); mysql_query($sql) or die(mysql_error()." Query: $sql"); } Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786917 Share on other sites More sharing options...
ngreenwood6 Posted March 17, 2009 Share Posted March 17, 2009 sorry thinking cap was off. The correct format would be this: customer_firstname = '".$_POST["customerupdate_firstname"]."' Thats just one example. you will have to change them all. Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786924 Share on other sites More sharing options...
Mundo Posted March 17, 2009 Author Share Posted March 17, 2009 Ignore this post, I can't delete! Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786925 Share on other sites More sharing options...
Mundo Posted March 17, 2009 Author Share Posted March 17, 2009 you can mix GET and POST...your use of them is fine is it producing an error or just not running the update? if there is an error, what is it? try this: if($_GET['module'] == "update" || isset($_POST['submitcustomerupdate'])) { $sql = printf("UPDATE customer SET customer_firstname = '%s', customer_lastname = '%s', customer_address1 = '%s', customer_address2 = '%s', customer_postcode = '%s', customer_dob = '%s', customer_email = '%s', customer_tel = '%s' WHERE customer_id = '%s'", mysql_real_escape_string($_POST['customerupdate_firstname']), mysql_real_escape_string($_POST['customerupdate_lastname']), mysql_real_escape_string($_POST['customerupdate_address1']), mysql_real_escape_string($_POST['customerupdate_address2']), mysql_real_escape_string($_POST['customerupdate_postcode']), mysql_real_escape_string($_POST['customer_dob']), mysql_real_escape_string($_POST['customerupdate_email']), mysql_real_escape_string($_POST['customerupdate_tel']), mysql_real_escape_string($_POST['customerupdate_id']) ); mysql_query($sql) or die(mysql_error()." Query: $sql"); } That gives me the following: UPDATE customer SET customer_firstname = 'Johm', customer_lastname = 'Hodges', customer_address1 = '122 Union Lane', customer_address2 = 'Chesterton', customer_postcode = 'CB4 1QB', customer_dob = '', customer_email = 'aaron@themungo.com', customer_tel = '07751224346' WHERE customer_id = ''You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '354' at line 1 Query: 354 Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786928 Share on other sites More sharing options...
Mundo Posted March 17, 2009 Author Share Posted March 17, 2009 sorry thinking cap was off. The correct format would be this: customer_firstname = '".$_POST["customerupdate_firstname"]."' Thats just one example. you will have to change them all. I have use queries such as mysql_query("SELECT * FROM customer WHERE '$_GET[customerupdate_id]' = customer_id"); without problem in the past, I dont think thats the problem at all. Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786931 Share on other sites More sharing options...
ngreenwood6 Posted March 17, 2009 Share Posted March 17, 2009 I didnt necessarily say that it was your only problem but you should always use the correct syntax when coding. Look around the forums and you will see that 9 out of 10 use either '' or "" around the $_POST. Obviously you dont care about doing it the right way just the fast way so good luck Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786942 Share on other sites More sharing options...
Mundo Posted March 17, 2009 Author Share Posted March 17, 2009 I think it's something to do with the WHERE part... Is that the wrong way around? Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786944 Share on other sites More sharing options...
rhodesa Posted March 17, 2009 Share Posted March 17, 2009 first...to settle this..you should ALWAYS use single or double quotes around your array keys. if you don't, you are actually calling the constant, which since the constant isn't defined it returns the name back. while it may work, you will get NOTICES if you have them on and then there is the case where your array key is actually a constant, which will mess everything up. anyways...Mundo...change printf() to sprintf() and try again...sorry Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786949 Share on other sites More sharing options...
ngreenwood6 Posted March 17, 2009 Share Posted March 17, 2009 first...to settle this..you should ALWAYS use single or double quotes around your array keys. if you don't, you are actually calling the constant, which since the constant isn't defined it returns the name back. while it may work, you will get NOTICES if you have them on and then there is the case where your array key is actually a constant, which will mess everything up. anyways...Mundo...change printf() to sprintf() and try again...sorry Thank you for clearing that up for him Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786951 Share on other sites More sharing options...
rhodesa Posted March 17, 2009 Share Posted March 17, 2009 actually...looking at it again...it seems like $_POST['customerupdate_id'] doesn't have a value...so i jumped to your form, and notice you have the value in a disabled element. disabled elements aren't passed with the data. make it a hidden element, remove the disabled part, and just print the customer id Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786953 Share on other sites More sharing options...
rhodesa Posted March 17, 2009 Share Posted March 17, 2009 Thank you for clearing that up for him i'm always happy to clear that particular point up. it's one of my biggest pet peeves when people don't put quotes around array keys Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786958 Share on other sites More sharing options...
Mundo Posted March 17, 2009 Author Share Posted March 17, 2009 actually...looking at it again...it seems like $_POST['customerupdate_id'] doesn't have a value...so i jumped to your form, and notice you have the value in a disabled element. disabled elements aren't passed with the data. make it a hidden element, remove the disabled part, and just print the customer id Yeh I just noticed this! I still wanted it to be visable but not editable, it's a shame I can't use the disabled attribute. Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786965 Share on other sites More sharing options...
ngreenwood6 Posted March 17, 2009 Share Posted March 17, 2009 Yeah me too, thats why I was trying to get him to put them in there but it just makes me laugh when someone comes here for help and you try to help them and they try to tell you that your wrong. I just think to myself well if you knew how to do it you wouldnt be here lol. Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786966 Share on other sites More sharing options...
Mundo Posted March 17, 2009 Author Share Posted March 17, 2009 first...to settle this..you should ALWAYS use single or double quotes around your array keys. if you don't, you are actually calling the constant, which since the constant isn't defined it returns the name back. while it may work, you will get NOTICES if you have them on and then there is the case where your array key is actually a constant, which will mess everything up. anyways...Mundo...change printf() to sprintf() and try again...sorry sprintf fixed everything, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/149843-solved-help-with-update-mysql-query/#findComment-786969 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.