lawler_09 Posted January 28, 2011 Share Posted January 28, 2011 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"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/225970-login-script/ Share on other sites More sharing options...
ChemicalBliss Posted January 28, 2011 Share Posted January 28, 2011 Can i just say please wrap code in [ php ] tags, eg: [ php ]code...[/ php] Also, can i ask why you are checkign multiple tables? are they all exactly the same tables (same columns/fields)? Quote Link to comment https://forums.phpfreaks.com/topic/225970-login-script/#findComment-1166590 Share on other sites More sharing options...
l4nc3r Posted January 28, 2011 Share Posted January 28, 2011 What is the problem, exactly? Quote Link to comment https://forums.phpfreaks.com/topic/225970-login-script/#findComment-1166597 Share on other sites More sharing options...
lawler_09 Posted January 28, 2011 Author Share Posted January 28, 2011 sorry is there anyway i can edit my post? and no they have different coloumns Quote Link to comment https://forums.phpfreaks.com/topic/225970-login-script/#findComment-1166598 Share on other sites More sharing options...
lawler_09 Posted January 28, 2011 Author Share Posted January 28, 2011 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"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/225970-login-script/#findComment-1166610 Share on other sites More sharing options...
Pikachu2000 Posted January 28, 2011 Share Posted January 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/225970-login-script/#findComment-1166614 Share on other sites More sharing options...
lawler_09 Posted January 28, 2011 Author Share Posted January 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/225970-login-script/#findComment-1166618 Share on other sites More sharing options...
BlueSkyIS Posted January 28, 2011 Share Posted January 28, 2011 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? definitely. Quote Link to comment https://forums.phpfreaks.com/topic/225970-login-script/#findComment-1166705 Share on other sites More sharing options...
ChemicalBliss Posted January 28, 2011 Share Posted January 28, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/225970-login-script/#findComment-1166716 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.