VictorVonKai Posted August 8, 2010 Share Posted August 8, 2010 Hi, I'm having an issue with a script should be getting data via POST from a form and then updating the data based a 2nd post variable. However, even though the post variables echo fine when I checked, they don't seem to work inside the update mysql query. I've checked on several websites and my syntax seems good. Please Help!! --Zach <?php $con = mysql_connect("localhost","NAME","PASSWORD"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("DB", $con); mysql_query("UPDATE DB SET value1 = $_POST['data1'] WHERE value = $_POST['data2']"); mysql_close($con); ?> [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/210106-mysql-update-query-isnt-getting-_post-data/ Share on other sites More sharing options...
Maq Posted August 8, 2010 Share Posted August 8, 2010 Most likely your query is invalid. What types of columns are 'value1' and 'value'? My guess is that your columns are a type that require single quotes around them. For a quick and dirty way to display mysql errors you can modify your code to this: mysql_query("UPDATE DB SET value1 = $_POST['data1'] WHERE value = $_POST['data2']") or die("Error: " . mysql_error()); For a better way and explanation of how to properly handle mysql errors you should read this - http://www.phpfreaks.com/blog/or-die-must-die. You should also sanitize your post values with mysql_real_escape_string. Quote Link to comment https://forums.phpfreaks.com/topic/210106-mysql-update-query-isnt-getting-_post-data/#findComment-1096510 Share on other sites More sharing options...
VictorVonKai Posted August 9, 2010 Author Share Posted August 9, 2010 The columns are both TEXT. Also, I added the debug code to from your previous post. However, I didn't get any output from it. Quote Link to comment https://forums.phpfreaks.com/topic/210106-mysql-update-query-isnt-getting-_post-data/#findComment-1096859 Share on other sites More sharing options...
PFMaBiSmAd Posted August 9, 2010 Share Posted August 9, 2010 The code you posted contains fatal parse/syntax errors due to putting array variables inside of a string. You would need to put {} around each {$_POST[...]} variable and you should be developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini (or a local php.ini or a .htaccess file) so that all the errors that php detects will be reported and displayed. You will save a ton of time. Also, since the values are apparently text, you would need to enclose them in single-quotes inside of the query to prevent sql syntax errors. mysql_query("UPDATE DB SET value1 = '{$_POST['data1']}' WHERE value = '{$_POST['data2']}'"); Quote Link to comment https://forums.phpfreaks.com/topic/210106-mysql-update-query-isnt-getting-_post-data/#findComment-1096861 Share on other sites More sharing options...
VictorVonKai Posted August 9, 2010 Author Share Posted August 9, 2010 Thank You!!! I have only been using php for about two months(I've been animating and coding in flash for about a year now) now, and this is part of my first real program in php. Quote Link to comment https://forums.phpfreaks.com/topic/210106-mysql-update-query-isnt-getting-_post-data/#findComment-1097044 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.