What am I doing wrong here?
Im planning to redirect a login to a page named administration.php if the user type = moderator..
And so i created a table named users with values in it….
Columns:
-
login
-
password
-
user_type
<?php error_reporting(E_ALL & ~E_NOTICE); ?> <?php session_start(); if( $_SESSION["logging"]&& $_SESSION["logged"]) { printme(); } else { if(!$_SESSION["logging"]) { $_SESSION["logging"]=true; loginform(); } else if($_SESSION["logging"]) { $number_of_rows=checkpass(); if($number_of_rows==1) { $_SESSION[user]=$_GET[userlogin]; $_SESSION[logged]=true; print"<h1>You have logged in successfully</h1><br/>"; print "<a href='logout.php'>Logout</a> | <a href='users.php'>Click to proceed</a>"; } else { print"<br/><br/>"; loginform(); } } } function loginform() { print ("<center><div id='login_header'><b><font face='Arial Black' color='black' size='4px'>Sign in to Minquep!</font></b></div></cen ter>"); print("<br/><br/>"); print ("<center><label>Username:</label><input type='text' name='userlogin' size='20'><br/><label>Password:</label><input type=' password' name='password' size='20'></center>"); print "<br/><input type='submit' value='Submit' name='submit' class='submit'>"; } function checkpass() { $dbHost = 'localhost'; $dbUser = 'root'; $dbPass = ''; $dbname = 'minquep_test'; $conn = mysql_connect($dbHost,$dbUser,$dbPass); // Connection Code mysql_select_db($dbname,$conn); // Connects to database $sql="select * from users where login='$_GET[userlogin]' and password='$_GET[password]'"; $result=mysql_query($sql,$conn) or die(mysql_error()); return mysql_num_rows($result); if ($result->user_type == "moderator"){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=pages/administration.php\">"; } } function content(){ print("<b><h1>hi mr.$_SESSION[user]</h1>"); print "<br><h2>only a logged in user can see this</h2>"; } function printme(){ } ?> </form>
From that code above^
Im trying to do the scenario but it doesn’t work..
if ($result->user_type == “moderator”){
echo “”;
note:
user_type is a column from table named users and I have a record which are the ff:
ID = 1
login = admin
password = shishi
user_type = moderator
Something like that..
how can I do that whenever a user logs in and he’s a moderator… he’ll automatically redirect to administration.php PAGE.
please help…
You are prematurely returning the number of rows of the resultset before getting to the moderator line.
Try this instead: