mjgdunne Posted April 18, 2008 Share Posted April 18, 2008 Hi i have written a php login script, i have two levels of users level 1/2 saved as level in database. I need the scripts to be able to check to see if they are a member and if so what level they are, if level one go to screen A and if level 2 then go to screen B. Any help would be greatly appreciated. Thanks. <?php session_start(); ini_set( 'display_errors', '1' ); error_reporting ( 2047 ); $host="localhost"; // Host name $username="root"; // Mysql username $password="root"; // Mysql password $db_name="test"; // Database name $tbl_name="members"; // Table name // Connect to server and select databse. mysql_connect("$host", "root", "root")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // username and password sent from signup form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $result = mysql_query($sql); if($result === false){ exit('db error: ' . mysql_error()); } // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // assign $_SESSION variables: $myusername, $mypassword and redirect to file "login_success.php" $userdata = mysql_fetch_row($result); //get the user row $_SESSION["myusername"] = $myusername; $_SESSION["mypassword"] = $mypassword; $_SESSION["mylevel"] = $mylevel; $debug = true; // Turn on DEBUGGING if($debug){ //for debug only echo 'myusername: ' . $_SESSION["myusername"] . "<br />\n"; echo 'mypassword: ' . $_SESSION["mypassword"] . "<br />\n"; echo 'mylevel : ' . $_SESSION["mylevel"] . "<br />\n"; exit(); } header("location:login_success.php"); } else { header("location:login_failure.php"); // echo "Wrong Username or Password"; } exit(); ?> Link to comment https://forums.phpfreaks.com/topic/101700-solved-login-script-problem/ Share on other sites More sharing options...
Fadion Posted April 18, 2008 Share Posted April 18, 2008 It should be pretty easy: <?php if($count == 1){ $valuesLogin = mysql_fetch_array($result); $mylevel = $valuesLogin['level']; $_SESSION['myusername'] = $myusername; $_SESSION['mypassword'] = $mypassword; $_SESSION['mylevel'] = $mylevel; if($mylevel == 1){ header('Location: screenA.php'); } else{ header('Location: screenB.php'); } } ?> Guess thats the way u wanted it. Link to comment https://forums.phpfreaks.com/topic/101700-solved-login-script-problem/#findComment-520296 Share on other sites More sharing options...
mjgdunne Posted April 18, 2008 Author Share Posted April 18, 2008 Thats great thanks, any idea how i could incorporate the else loginfailure when the wrong password username combo is entered? Link to comment https://forums.phpfreaks.com/topic/101700-solved-login-script-problem/#findComment-520308 Share on other sites More sharing options...
Fadion Posted April 18, 2008 Share Posted April 18, 2008 <?php if($count == 1){ $valuesLogin = mysql_fetch_array($result); $mylevel = $valuesLogin['level']; $_SESSION['myusername'] = $myusername; $_SESSION['mypassword'] = $mypassword; $_SESSION['mylevel'] = $mylevel; if($mylevel == 1){ header('Location: screenA.php'); } else{ header('Location: screenB.php'); } } else{ header('Location: login_failure.php'); } ?> Its the same way u used it, i just added the if/else for $mylevel. Link to comment https://forums.phpfreaks.com/topic/101700-solved-login-script-problem/#findComment-520310 Share on other sites More sharing options...
mjgdunne Posted April 18, 2008 Author Share Posted April 18, 2008 Thanks thats working perfectly now Link to comment https://forums.phpfreaks.com/topic/101700-solved-login-script-problem/#findComment-520325 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.