Jump to content


Photo

MYSQL Problems


  • This topic is locked This topic is locked
5 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 09 August 2006 - 01:57 PM

Hi,
I have a config file which Is attached to every page, within
this config file I have a website closed script, this allows
the admins to turn it on or off. the problem is with the SQL

I have created it to check the users rank from a database
if the rank is not an admin then they are redirected to my
closed page. However, when a member is not signed in
it doesn't affect them, neither does it if they are signed in.

Is there any way around it?

My code is...
$ssql = mysql_query("SELECT usr_rank FROM accounts WHERE usr_user='{$_SESSION['username']['usr_user']}'");
		while( $sdat = mysql_fetch_array($ssql, MYSQL_NUM))
		{
			if( $sdat[0] != admin )
			{
			$sql = mysql_query("SELECT func_value FROM options WHERE op_id='1' AND func_name='web'");
			while( $data = mysql_fetch_array($sql, MYSQL_NUM))
				{
				$lock = $data[0];
				if( $lock == y )
					{
					echo '<meta http-equiv="REFRESH" content="0;URL=closed/index.php">';
					exit;
					}
				}
			}else{
		echo '<div align="center">
  <center>
  <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="50%" background="../template/images/bgmain.gif" height="20" bgcolor="#FFFFFF">
    <tr>
      <td width="100%">
      <p align="center"><b><font size="1" face="Verdana">MAINTENANCE MODE</font></b></td>
    </tr>
  </table>
  </center>
</div>';
		}
	}


#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 09 August 2006 - 02:04 PM

yep before the query you could put an if statement.

If no session the redirect to closed page.

the query shoudl only retuen one result so get rid of the while loops.

you if statement to see if they are admin is missing quotes around teh string.... 'admin' as is the lock if statement.....
follow me on twitter @PHPsycho

#3 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 09 August 2006 - 02:06 PM

Thanks for the advice :].
and...
it doesn't need quotes Unless it has a space or there is more than one variable like using && or ||

#4 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 09 August 2006 - 02:10 PM

I can see a couple of possible problems here.

First, you don't have 'admin' and 'y' in quotations in your conditionals.

Second, I'm not sure that -

echo '<meta http-equiv="REFRESH" content="0;URL=closed/index.php">';

-will result in a redirect (if it does, I've learned something new-thanks). 

You might try header("Location:yourdomain.com/closed/index.php"); instead.


#5 bltesar

bltesar
  • Members
  • PipPipPip
  • Advanced Member
  • 109 posts

Posted 09 August 2006 - 02:11 PM

correction, try try header("Location:http://www.yourdomain.com/closed/index.php"); instead.


#6 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 09 August 2006 - 02:14 PM

1. my if statements don't need quotes " or ' i've tested it. 2. the META will redirect.
because: 1. it's a HTML tag. and 2. if the headers are sent with Sessions, cookies or <head> using the META is the other solution to redirecting :/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users