Page 1 of 1

login script

Posted: Fri Jan 28, 2011 1:34 pm
by lawler_09
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!

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

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

Code: Select all

<?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");
   }
   }   
?>

Re: login script

Posted: Fri Jan 28, 2011 8:16 pm
by Pazuzu156
By the look of the code, you haven't connected to a database.

Code: Select all

<?php
$host = "localhost";
$user = "root";
$pass = "";
$database = "db_name";
$table = "tbl_name";

$connect = mysql_connect("$host","$user","$pass") or die ("Cannot connect to database host");
$selDB = mysql_select_db("$database") or die ("Cannot find database");
$queryget = mysql_query("SELECT * FROM $table") or die ("Invalid Query");
?>
If you are looking for a good help, here is a link you should check out: http://www.youtube.com/watch?v=4oSCuEtxRK8

Re: login script

Posted: Sat Jan 29, 2011 3:29 pm
by phazorRise
It should not be done like this.
First create fifth table and create three columns. First two for email and password. Thirds column for the type of account they belong to. Check this table for any entry instead of traversing through all four tables. And if both email and password match with user entered values then reteive third column value and based upon that redirect user to his destination.
as a new user is register make an entry in fifth table also with his account type.