Jump to content

Another header problem!


a1amattyj

Recommended Posts

Hello,

 

This little code, checks for the ip in the mysql database, if its wrong, goes to login, if right, just update with the current ip.

 

function UpdateIp($username){

      require("../multi_operations/config_inc.php");

      $ip = getenv("REMOTE_ADDR");  

      $query = "SELECT FROM multi_admins WHERE username = '$username'";
      $result = mysql_query($query);
      if($row = mysql_fetch_array($result)){

      if($row['ip'] == $ip){
          //Do nothing
      }else{
         session_destroy();
         header("location:login.php");
      }


      $query = "UPDATE multi_admins SET ip = '$ip' WHERE username = '$username'";
      $result = mysql_query($query);
      }else{
         session_destroy();
         header("location:login.php");
      }

}

 

 

php error:

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/./public_html/multi_operations/admin_functions.php on line 154

 

Warning: Cannot modify header information - headers already sent by (output started at /home/./public_html/multi_operations/admin_functions.php:154) in /home/./public_html/multi_operations/admin_functions.php on line 168

 

Any ideas? If i see this message, and try to click any other action, my session check logs them out ^. Can i do a javascript redirect instead of the header location? Or is that not safe.. seeming you can disable it?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/110228-another-header-problem/
Share on other sites

Fix your first error and the last one will go away.

 

As for why you get this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/./public_html/multi_operations/admin_functions.php on line 154

 

You most probably have  an error in your SQL Query. Change

$result = mysql_query($query);

to

$result = mysql_query($query) or die('MySQL Error: ' . mysql_error());

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.