Jump to content

login script


lawler_09

Recommended Posts

hi guys,

 

any help will be much appreciated!!

 

basically i have a login script, that i want to check mutliple tables and i am stuggling to get it to work!

 

what i have is basically:

 

 

<?php

session_start();

$_SESSION['loggedin'] = false;

include("functions.php");

extract($_POST);

 

$query = "SELECT * From table1 WHERE email='$email' and password='$password';";

$result = doQuery($query);

if($result==false) {

 

$query = "SELECT * From table2 WHERE email='$email' and password='$password';";

$result = doQuery($query);

if($result==false) {

 

 

$query = "SELECT * From table3 WHERE email='$email' and password='$password';";

$result = doQuery($query);

if($result==false) {

 

 

 

$query = "SELECT * From table4 WHERE email='$email' and password='$password';";

$result = doQuery($query);

if($result==false) {

 

} else {

if(mysql_num_rows($result)) {

$row = mysql_fetch_assoc($result);

$_SESSION['loggedin'] = true;

$_SESSION['id'] = $_POST['id'];

header("Location:1");

} else {

header("Location:wrong.php");

}

}

 

} else {

if(mysql_num_rows($result)) {

$row = mysql_fetch_assoc($result);

$_SESSION['loggedin'] = true;

$_SESSION['id'] = $_POST['id'];

header("Location:2");

} else {

header("Location:wrong.php");

}

}

 

} else {

if(mysql_num_rows($result)) {

$row = mysql_fetch_assoc($result);

$_SESSION['loggedin'] = true;

$_SESSION['id'] = $_POST['id'];

header("Location:3");

} else {

header("Location:wrong.php");

}

}

 

} else {

if(mysql_num_rows($result)) {

$row = mysql_fetch_assoc($result);

$_SESSION['loggedin'] = true;

$_SESSION['id'] = $_POST['id'];

header("Location:4");

} else {

header("Location:wrong.php");

}

}

?>

Link to comment
Share on other sites

What is the problem, exactly?

 

when someone enters an email address and password, i want the script to check each of the 4 tables for what was entered, and then forward them somewhere depending on which table it was found in, or if it wasnt found in any then to another page

 


<?php
   session_start();
   $_SESSION['loggedin'] = false;
   include("functions.php");
   extract($_POST);
   
   $query = "SELECT * From table1 WHERE email='$email' and password='$password';";
   $result = doQuery($query);
   if($result==false)   {
      
      $query = "SELECT * From table2 WHERE email='$email' and password='$password';";
   $result = doQuery($query);
   if($result==false)   {
      
      
      $query = "SELECT * From table3 WHERE email='$email' and password='$password';";
   $result = doQuery($query);
   if($result==false)   {
      
      
      
      $query = "SELECT * From table4 WHERE email='$email' and password='$password';";
   $result = doQuery($query);
   if($result==false)   {
      
   }   else {
         if(mysql_num_rows($result))   {
            $row = mysql_fetch_assoc($result);
            $_SESSION['loggedin'] = true;
            $_SESSION['id'] = $_POST['id'];
            header("Location:1");
   }   else {
         header("Location:wrong.php");
   }
   }   
      
   }   else {
         if(mysql_num_rows($result))   {
            $row = mysql_fetch_assoc($result);
            $_SESSION['loggedin'] = true;
            $_SESSION['id'] = $_POST['id'];
            header("Location:2");
   }   else {
         header("Location:wrong.php");
   }
   }   

   }   else {
         if(mysql_num_rows($result))   {
            $row = mysql_fetch_assoc($result);
            $_SESSION['loggedin'] = true;
            $_SESSION['id'] = $_POST['id'];
            header("Location:3");
   }   else {
         header("Location:wrong.php");
   }
   }   
         
   }   else {
         if(mysql_num_rows($result))   {
            $row = mysql_fetch_assoc($result);
            $_SESSION['loggedin'] = true;
            $_SESSION['id'] = $_POST['id'];
            header("Location:4");
   }   else {
         header("Location:wrong.php");
   }
   }   
?>

Link to comment
Share on other sites

It would make so much more sense to use one table, and a value in a field in that table to indicate what to do when that user logs in.

 

really?

 

its for a college project, and basically theres 4 different types of accounts, with different fields in each.

 

when they log in, it picks up what kind of account they have, and takes them to a seperate account page for that particular type of account.

Link to comment
Share on other sites

You may need to learn a bit more about database design.

 

Specifically, Relational Data

 

You want a couple tables but you only use a single query. I would reccommend to google something like "Tutorial PHP MySQL JOIN", or if you enjoy reading something like "Relational Database Basics".

 

Your tables would be like;

1. Your account Types (Holding where people get forwarded too for example)

2. Your Users (There would be a special field called something like "account_type_id", this would be the id number of an item in the above table.

 

Your query would be something like:

SELECT `table_accounttypes`.`redirect_url` 
FROM `table_users` 
INNER JOIN `table_accounttypes` ON `table_accounttypes`.`id`=`table_users`.`account_type_id`
WHERE `table_users`.`username`='$someuser' AND `table_users`.`password`='$somepass'

 

Hope this helps, good luck

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.