matt_jo84 Posted March 17, 2007 Share Posted March 17, 2007 I have been having problems with updating a table of mine for the past few days and cannot find a solution or reason why it is not working. What happens with the code below is a user logs in so an query is made to update their login status to 1 (0 = logged out, 1 = logged in). Then to make sure that the update to the database is made there is a check to see if it has been changed to 1 before the page is redirected to logged_IN.htm (the code below does find $login_num = 1). The problem is that in the table after the header function is executed. The value for login never changed to 1 in the table, it is always still 0. If I remove the header and have it not redirect to another page the login value in the table does change to 1. I have tried using 2 different servers also and still have no luck. Please help me out if you can, thanks. mysql_query("UPDATE " . $table . " SET login = '1' WHERE password = '$pass'"); $query_login = mysql_query("SELECT login FROM " . $table . " WHERE password = '$pass' "); $login_num = mysql_result($query_login, 0); if($login_num == '1') { header( "Location: http://www.website.com/logged_IN.htm" ); } Link to comment https://forums.phpfreaks.com/topic/43168-problem-with-update-to-table/ Share on other sites More sharing options...
suzzane2020 Posted March 17, 2007 Share Posted March 17, 2007 Try exracting the field by either a mysql_fetch_array or row and then check the value Link to comment https://forums.phpfreaks.com/topic/43168-problem-with-update-to-table/#findComment-209617 Share on other sites More sharing options...
matt_jo84 Posted March 17, 2007 Author Share Posted March 17, 2007 Ok I tried using the following code with the mysql_fetch_row function. $check[0] always turns out to be 1 so it always makes it into the if statement. I ran the code twice. The first time with the header function and it once again did not update the login to 1 in my table. The second time I ran the code with the header function removed and the echo statement below and it did update the login to 1 on the table. No luck with that, but thanks for the reply. mysql_query("UPDATE " . $table . " SET login = '1' WHERE password = '$pass'"); $query_login = mysql_query("SELECT login FROM " . $table . " WHERE password = '$pass' "); $check = mysql_fetch_row($query_login); if($check[0] == '1') { //echo("It Updated"); header( "Location: http://www.website.com/logged_IN.htm" ); } Link to comment https://forums.phpfreaks.com/topic/43168-problem-with-update-to-table/#findComment-209627 Share on other sites More sharing options...
suzzane2020 Posted March 17, 2007 Share Posted March 17, 2007 This was the code i used and it worked..just change the feildnames where required mysql_query("UPDATE users SET login = '1' WHERE pwd = 'codex'"); $query_login = mysql_query("SELECT login FROM users WHERE pwd = 'codex' "); $rw = mysql_fetch_array($query_login); if($rw["login"] == 1) { echo("It Updated"); header( "Location: http://www.website.com/logged_IN.htm" ); } Link to comment https://forums.phpfreaks.com/topic/43168-problem-with-update-to-table/#findComment-209634 Share on other sites More sharing options...
matt_jo84 Posted March 17, 2007 Author Share Posted March 17, 2007 Tried everything as you have it and it still does the same thing. The funny thing with all this is that this same script use to work at one time and why it doesn't work right anymore I can't figure out. Link to comment https://forums.phpfreaks.com/topic/43168-problem-with-update-to-table/#findComment-209640 Share on other sites More sharing options...
PC Nerd Posted March 17, 2007 Share Posted March 17, 2007 ok. i dont know for certain, but when you echo out the query what does it say??? also, if it isnt pervent or it isnt displaying parts of the query, look and see if there are any variables, if so change "...='$Var'" to ".......='".$Var."'"; good luck Link to comment https://forums.phpfreaks.com/topic/43168-problem-with-update-to-table/#findComment-209655 Share on other sites More sharing options...
matt_jo84 Posted March 18, 2007 Author Share Posted March 18, 2007 I found something interesting out that I am going to be looking into. I tried having the header redirect to a different website than the one I had in the code (like google.com). Everything updated fine. Link to comment https://forums.phpfreaks.com/topic/43168-problem-with-update-to-table/#findComment-209669 Share on other sites More sharing options...
matt_jo84 Posted March 18, 2007 Author Share Posted March 18, 2007 Ok, well all of the files that I have been working with are in a folder on a server called "registry". It turns out that the update to the table works as long as you redirect to a file that is outside of the current folder ("registry"). I guess problem solved, but is this right? note: I am using session variables, don't know if that makes a difference or not. Link to comment https://forums.phpfreaks.com/topic/43168-problem-with-update-to-table/#findComment-209680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.