abdulbasit29 Posted December 29, 2014 Share Posted December 29, 2014 Below code is working fine but i need to redirect on 3 different pages and its giving me error. My table structure is as User table Email Password admin@yahoo.com 123 tariq@yahoo.com 987 bilal@yahoo.com 456 if user name is like; admin@yahoo.com the page should redirect on welcome.php if user name is like; info@aiousoft.com the page should redirect to welcome2.php and if user doesnot exist in database then give error as ELSE "user doesnot exist" thanks signin.php <html><head><title>Sign In</title></head><body><?php include 'header.php'; ?><?php include 'menu.php'; ?><center><form method="post" action="checklogin.php"> <h3>Please Signin</h3> <table width="400" border="0"> <tr><td>Email</td> <td><input name="email" type="text" id="email"></td></tr> <tr><td>Password</td> <td><input name="password" type="password" id="password"></td></tr> </table> <p><label> <input type="submit" email="submit" value="Submit"> </label><input email="reset" type="reset"> </p> </form></center></body></html> checklogin.php <html><head><title>Check Login</title></head><body><?phpinclude 'header.php';include 'menu.php'; $email=$_POST['email'];$password=$_POST['password']; @ $db = mysql_pconnect('localhost', 'root', '');if (!$db){ echo 'Error: Could not connect to database. Please try again later.';exit;}mysql_select_db('car');$q=mysql_query("select * from user where email='".$email."' and password='".$password."' ") or die(mysql_error());$res=mysql_fetch_row($q);if($res){ header('location:welcome.php');}else{ echo' Please signin again as your user name and password is not valid';}?></body></html> header.php menu.php Quote Link to comment https://forums.phpfreaks.com/topic/293493-user-authentication-help-by-using-if-elseif-and-else-statement-and-redirect-page-on-3-differnet-urls/ Share on other sites More sharing options...
CroNiX Posted December 29, 2014 Share Posted December 29, 2014 What error are you getting? It seems it would be best to add a new column to your db's user table and hold the script name that you want that user to redirect to. Then when the user logs in redirect them to that page instead of in an if/else block. In your else statement above, you have a misplaced quote in the echo statement (no space between echo and first quote) Quote Link to comment https://forums.phpfreaks.com/topic/293493-user-authentication-help-by-using-if-elseif-and-else-statement-and-redirect-page-on-3-differnet-urls/#findComment-1501056 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.