mongoose00318 Posted August 16, 2010 Share Posted August 16, 2010 Ok, I'm going start off simple. If I have to provide more code I will. I am doing an update on a table called countries. Yet my query just will not update the db. Is there anything wrong with this query? mysql_query("UPDATE countries SET country_id = '{$_POST['update_value']}' WHERE country_id = '{$_POST['original_html']}'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/210899-help-with-mysql-update-querycant-see-what-the-heck-is-going-wrong/ Share on other sites More sharing options...
btherl Posted August 16, 2010 Share Posted August 16, 2010 Are you sure the query is being executed? You can try adding a print statement just before it, such as print "About to set country_id to {$_POST['update_value']} for country_id {$_POST['original_html']}<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/210899-help-with-mysql-update-querycant-see-what-the-heck-is-going-wrong/#findComment-1100007 Share on other sites More sharing options...
mongoose00318 Posted August 16, 2010 Author Share Posted August 16, 2010 Do you mean are those post values set and have value? I have checked that and they both show up if I print or echo them. Thats why I'm so frustrated. Quote Link to comment https://forums.phpfreaks.com/topic/210899-help-with-mysql-update-querycant-see-what-the-heck-is-going-wrong/#findComment-1100008 Share on other sites More sharing options...
mongoose00318 Posted August 16, 2010 Author Share Posted August 16, 2010 Can I provide more info to help? Maybe the whole script? Quote Link to comment https://forums.phpfreaks.com/topic/210899-help-with-mysql-update-querycant-see-what-the-heck-is-going-wrong/#findComment-1100010 Share on other sites More sharing options...
btherl Posted August 16, 2010 Share Posted August 16, 2010 I also want to check if the query is being executed. That's the first step to debugging why it's not updating. If it's being executed and it's still not updating, then it's time to look at the query itself. Yes the whole script will help And also a brief description of the circumstances in which the update should be triggered. Quote Link to comment https://forums.phpfreaks.com/topic/210899-help-with-mysql-update-querycant-see-what-the-heck-is-going-wrong/#findComment-1100011 Share on other sites More sharing options...
mongoose00318 Posted August 16, 2010 Author Share Posted August 16, 2010 Ok I know what you mean now. I added a echo "hello"; under the query and that showed up fine. Here is the code. <?php $value = $_POST['update_value']; include('dbconfig.php'); //edit department if($_GET['mode'] != "delete") { //get requested departments information from database $exist_query = mysql_query("SELECT * FROM countries WHERE {$_GET['mode']}='{$_POST['update_value']}'") or die(mysql_error()); //edit department name //if $exist_query = 0 or $exist_query = 1 and $_GET['mode'] = name if(mysql_num_rows($exist_query) == 0) { if($_GET['mode'] == "country_name") { mysql_query("UPDATE countries SET country_name = '{$_POST['update_value']}' WHERE country_name = '{$_POST['element_id']}'") or die(mysql_error()); echo $_POST['update_value']; //echo $_POST['element_id']; } //edit department description //if $exist_query = 0 or $exist_query = 1 and $_GET['mode'] = description elseif($_GET['mode'] == "country_id") { mysql_query("UPDATE countries SET country_id = '{$_POST['update_value']}' WHERE country_id = '{$_POST['original_html']}'") or die(mysql_error()); echo "hello"; die(); /* //search for users that have state that was being edited and change it to the new value $get_users = mysql_query("SELECT * FROM users WHERE country = '{$_POST['original_html']}'") or die(mysql_query()); //check to see that the users state is set to the old state value, if it is replace it with the new state value while($row = mysql_fetch_array($get_users)) { if($row['country'] == $_POST['original_html']) { mysql_query("UPDATE users SET country = '{$_POST['update_value']}' WHERE user_id = '{$row['user_id']}'") or die(mysql_error()); } } //update the states country id field mysql_query("UPDATE states SET country_id = '{$_POST['update_value']}' WHERE country_id = '{$_POST['original_html']}'") or die(mysql_query()); */ echo $_POST['update_value']; } } //the update value the user tried to enter already exists in the database else { //alert the user of the problem echo "The entry already exists"; } } //delete department elseif($_GET['mode'] == "delete") { //delete the department mysql_query("DELETE FROM countries WHERE country_id = '".$_GET['country_id']."'"); //redirect user header("Location: ../admin_manage_countries.php"); } ?> Look at this part. elseif($_GET['mode'] == "country_id") { mysql_query("UPDATE countries SET country_id = '{$_POST['update_value']}' WHERE country_id = '{$_POST['original_html']}'") or die(mysql_error()); echo "hello"; die(); The "hello" is showing up, and the $_POST vars are showing up. What else can I provide to help you? Quote Link to comment https://forums.phpfreaks.com/topic/210899-help-with-mysql-update-querycant-see-what-the-heck-is-going-wrong/#findComment-1100013 Share on other sites More sharing options...
mongoose00318 Posted August 16, 2010 Author Share Posted August 16, 2010 I even changed the POST vars to just static information and the query didnt do anything. But if I removed the single quotes from around the POST vars I get a mysql error. It just doesn't make any sense because I have another page that is really similar that is working fine. EDIT** Your print statement worked also. Heres the result. About to set country_id to USA2 for country_id hello Quote Link to comment https://forums.phpfreaks.com/topic/210899-help-with-mysql-update-querycant-see-what-the-heck-is-going-wrong/#findComment-1100015 Share on other sites More sharing options...
btherl Posted August 16, 2010 Share Posted August 16, 2010 OK, the next step I would do is to change this mysql_query("UPDATE countries SET country_id = '{$_POST['update_value']}' WHERE country_id = '{$_POST['original_html']}'") or die(mysql_error()); to this $sql = "UPDATE countries SET country_id = '{$_POST['update_value']}' WHERE country_id = '{$_POST['original_html']}'"; print "About to execute '$sql'<br>"; mysql_query($sql) or die(mysql_error()); So we can see exactly what query is getting executed. Quote Link to comment https://forums.phpfreaks.com/topic/210899-help-with-mysql-update-querycant-see-what-the-heck-is-going-wrong/#findComment-1100019 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.