Jump to content

[SOLVED] reloading a page in IF statement / PHP


thisisnuts123

Recommended Posts

hello guys

 

 

if ( $turns == 0 ) {

	}

 

if i wana reload a page if this statement if true, with out the user havign to click any thing how can this be done?

 

 

i tried

 

if ( $turns == 0 ) {
header('Location: main.php'); 
die(); 
	}

 

it doesn;t seem to be working]

function turns()
{
       	$query1  = "SELECT `turns` FROM user WHERE `username` = '$_SESSION[user]' ";
$result1 = mysql_query($query1);
$row1 = mysql_fetch_row($result1);
             $turn[0] = $row1[0];
$turns = $turn[0];
             if ( $turns == 0 ) {
  	header('Location: login.php'); 
             die(); 
}
             elseif {   .... etc etc....
             }
return $turns;			
}			

Theres allot of useless code in that function. Allong with absolutely no error handling. Try...

 

<?php

function turns() {
 $sql  = "SELECT `turns` FROM user WHERE `username` = '{$_SESSION['user']}'";
 if ($result = mysql_query($sql)) {
   if (mysql_num_rows($result)){
     $row = mysql_fetch_assoc($result);
     if (!$row['turns']) {
       header('Location: login.php'); 
       die(); 
     } else {
        return $row['turns'];
     }			
   }
 }
}

?>	

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.