PHP How-ToPost your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the PHP How-To section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
Hi I have created a login page(auth.php) where both users(student) and admin can login where the data is matched from the two tales in mysql database. The only problem is that when both types of users sucessfully login, they are directed to the index page. I would like the admin users to be directed to an admin home page instead (admin_index) and am unsure on how to do this.
If anyone can help mw with this by adjusting the code or otherwise then i would be very grateful. Thanks!
<?
// Login & Session
// auth.php
// select database
include("mysql_connect.php");
// start session
session_start();
// convert username and password from _POST or _SESSION
if($_POST){
$_SESSION['username']=$_POST["username"];
$_SESSION['password']=$_POST["password"];
}
// query for matching username and password for all users
$query="SELECT student.username, student.password, staff.username, staff.password
FROM student, staff
WHERE student.username='" . $_SESSION['username'] . "' and student.password='" . $_SESSION['password'] . "'
OR staff.username='" . $_SESSION['username'] . "' and staff.password='" . $_SESSION['password'] . "'";
$results=mysql_query ($query)
or die(mysql_error());
// retrieve number of rows resulted
$num=mysql_num_rows($results);
// print login form and exit if failed.
//This will only appear in the login page and won't show on subsequent pages when auth is called.
if($num < 1){
echo "<H1><P><Center>Login</H1></P></Center>";
echo "<center>You are not authenticated. Please login.<br><br>