Jump to content

Problem with UPDATE to table


matt_jo84

Recommended Posts

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

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" );

        }

 

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" );

        }

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.