rainemaida Posted April 2, 2007 Share Posted April 2, 2007 Currently I have a login script that takes the user to a page after they have logged in. However, I would like to modify it so that if someone with status = 's' in the user table gets taken to one page and if you're not status 's' then u get taken to another. if (isset($_POST['submitted'])) { require_once ('db_connect.php'); $errors = array(); // checks for username if (empty($_POST['userID'])) { $errors[] = 'You forgot to enter your username.'; } else { $u = $_POST['userID']; } //checks for password if (empty($_POST['password'])) { $error[] = 'You forgot to enter your password.'; } else { $p = $_POST['password']; } if (empty($errors)) { $query = "SELECT userID, password FROM user WHERE userID='$u' AND password='$p'"; $result = @mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); if ($row) { setcookie('login', $row[0], time()+2400, '/', '', 0); session_name('login_id'); session_start(); $_SESSION['userID'] = $row[0]; $_SESSION['password'] = $row[1]; header("Location: coursedocumentsstaff.php"); exit(); } else { $errors[] = 'An error occurred while the system was processing this login request.'; } } mysql_close(); } status is a row in the user table but i didn't add it in the select statement to save any confusion for someone who is going to help out. Cheers, Steve Link to comment https://forums.phpfreaks.com/topic/45271-solved-login-problem/ Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 Well, you need to select it in your query, then use something like.... <?php if ($row['status'] == 's') { header('Location: sindex.php'); } else { header('Location: index.php'); } ?> Link to comment https://forums.phpfreaks.com/topic/45271-solved-login-problem/#findComment-219819 Share on other sites More sharing options...
rainemaida Posted April 2, 2007 Author Share Posted April 2, 2007 I added it like this // checks for username if (empty($_POST['userID'])) { $errors[] = 'You forgot to enter your username.'; } else { $u = $_POST['userID']; } //checks for password if (empty($_POST['password'])) { $error[] = 'You forgot to enter your password.'; } else { $p = $_POST['password']; } if (empty($errors)) { $query = "SELECT userID, password, status FROM user WHERE userID='$u' AND password='$p'"; $result = @mysql_query ($query); $row = mysql_fetch_array ($result, MYSQL_NUM); if ($row) { setcookie('login', $row[0], time()+2400, '/', '', 0); session_name('login_id'); session_start(); $_SESSION['userID'] = $row[0]; $_SESSION['password'] = $row[1]; if ($row['status'] == 's') { header('Location: coursedocumentsstaff.php'); } else { header('Location: coursedocumentsstudent.php'); } exit(); } else { $errors[] = 'An error occurred while the system was processing this login request.'; } } however when the person with status "s" logs in it still goes to coursedocumentsstudent.php and not the staff one. Any ideas? Cheers, Steve Link to comment https://forums.phpfreaks.com/topic/45271-solved-login-problem/#findComment-219823 Share on other sites More sharing options...
trq Posted April 2, 2007 Share Posted April 2, 2007 It shouldn't. Print $row['status'] just prior to make sure. die($row['status']); if ($row['status'] == 's') { header('Location: coursedocumentsstaff.php'); } else { header('Location: coursedocumentsstudent.php'); } Link to comment https://forums.phpfreaks.com/topic/45271-solved-login-problem/#findComment-219824 Share on other sites More sharing options...
rainemaida Posted April 2, 2007 Author Share Posted April 2, 2007 When I add die($row['status']); Nothing comes up when I click login. I'm fairly new to PHP so I'm not sure if that's what you wanted me to do. Please advise. Cheers, Steve Link to comment https://forums.phpfreaks.com/topic/45271-solved-login-problem/#findComment-219840 Share on other sites More sharing options...
rainemaida Posted April 2, 2007 Author Share Posted April 2, 2007 I've just spoke to my mate and he said to use $row[2] instead of status and it worked! Thank you for all the help anyway, it's really appreciated. Cheers, Steve Link to comment https://forums.phpfreaks.com/topic/45271-solved-login-problem/#findComment-219845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.