Jump to content
abdulbasit29

User authentication HELP by using IF ELSEIF and ELSE statement and redirect page on 3 differnet urls

Recommended Posts

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>
<?php
include '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

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.