aian04 Posted October 2, 2007 Share Posted October 2, 2007 <?php $time = time() + 3600; setcookie("ID",$_POST['id'], $time); setcookie("pass",$_POST['password'], $time); ?> <html> <head> <link href="interface design/css.css" rel="stylesheet" type="text/css"></head> <body> <?php #connect to MySQL Server @mysql_pconnect('localhost', 'root', 'tmc') or die(mysql_error()); #connect to database @mysql_select_db('tgp') or die(mysql_error()); // if form has been submitted // makes sure they filled it in if(!$_POST['id'] | !$_POST['password']) {?> <p class="error">Login Failed!<br>Please Type your Username and Password agian!</p> <?php } // checks it against the database $query = mysql_query("SELECT * FROM member WHERE Cid = '".$_POST['id']."'")or die(mysql_error()); $query2 = mysql_query("SELECT * FROM member WHERE staffID = '".$_POST['id']."'")or die(mysql_error()); $separator = $query, $query2; //Gives error if user dosen't exist $row = mysql_num_rows($query); $row2 = mysql_num_rows($query2); if ($row == 0) {?> <p class="error">Unauthorized Personnel</p> <?} and if ($row2 == 0) {?> <p class="error">Unauthorized Personnel</p> <?} if($separator == $query) { while($list = mysql_fetch_array( $query )) { //gives error if the password is wrong if ($_POST['password'] != $list['password']) {?> <script>window.location ="login2.html"</script> <?} else { ?> <script> window.location="interface design/member.php" </script> <?php } } } else if ($separator == $query2) { while($list = mysql_fetch_array( $query2 )) { if ($_POST['password'] != $list['password']) {?> <script>window.location ="login2.html"</script> <?} else // if login is ok then we add a cookie if ($list['userlvl'] == "admin"){ //testing where to go if correct ?> <script> window.location="interface design/home.html" </script> <?php } else if($list['userlvl'] == "staff"){ ?> //this is just testing if correct where to go.. <script>window.location = "interface design/room.html";</script> <?} } ?> ok heres the question... i created one login page form... to validate the login form i use php.. and i have two different tables a staff table and a member table.. both have id and password then i want to check for the id if its from staff table or member table... im having a difficulty hir.. pls help me phpfreakers... Quote Link to comment https://forums.phpfreaks.com/topic/71538-solved-guys-i-nid-help-im-a-php-beginner/ Share on other sites More sharing options...
MmmVomit Posted October 2, 2007 Share Posted October 2, 2007 You might want to rethink how the database itself is structured. Staff are people, and members are people. In general, you want one table to store info about people. Just have a column in the table that tells you whether the person is a member or staff. This way you only have to run one query, then check the value of a column to decide what action to take next. This will also make it much easier to ensure that a staff and member don't choose the same login name. Quote Link to comment https://forums.phpfreaks.com/topic/71538-solved-guys-i-nid-help-im-a-php-beginner/#findComment-360183 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 First a question: Why do you have 2 tables! why not 1 table with a field for accesslevel (1-5) 1=admin 5=guess sort of thing ? if not try this <?php $Level = 0; $ID = (int)$_POST['id']; //i assume Cid & staffID are INT's (if their string change to ='$ID'" $query = mysql_query("SELECT * FROM member WHERE Cid = $ID")or die(mysql_error()); $row = mysql_num_rows($query); $C = mysql_num_rows($query); if($C >0) { $Level = 1; } $query = mysql_query("SELECT * FROM member WHERE staffID = $ID")or die(mysql_error()); $row = mysql_num_rows($query); $C = mysql_num_rows($query); if($C >0) { $Level = 2; } switch($Level) { default: case 0: echo "No Access"; break; case 1: echo "Member"; break; case 2: echo "Staff"; break; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71538-solved-guys-i-nid-help-im-a-php-beginner/#findComment-360185 Share on other sites More sharing options...
MadTechie Posted October 2, 2007 Share Posted October 2, 2007 This will also make it much easier to ensure that a staff and member don't choose the same login name. Thats a perfect point.. EDIT: i'll admit i have created a System and used 2 extra tables for "extended info" and of different types but it makes management much harder, having to use JOINs to view the correct data and updates are a nightmare at times.. Quote Link to comment https://forums.phpfreaks.com/topic/71538-solved-guys-i-nid-help-im-a-php-beginner/#findComment-360190 Share on other sites More sharing options...
MmmVomit Posted October 2, 2007 Share Posted October 2, 2007 In our big database here at work, there are several tables like this, and they simply contain ALL columns that may be used on any type of record. For example, one table stores both individuals and organizations. An individual has a first, last and middle name, but an organization just has an organization name. These are four different fields. The fields that aren't needed for a particular record are simply left NULL. Both approaches have their problems, and I'm not sure which one I prefer. Quote Link to comment https://forums.phpfreaks.com/topic/71538-solved-guys-i-nid-help-im-a-php-beginner/#findComment-360196 Share on other sites More sharing options...
aian04 Posted October 2, 2007 Author Share Posted October 2, 2007 ok ur suggesting me to create 1 table only.. i create 2 table bcoz in member table got many info but in staff only few.. is there a way to find a solution in my case? or should i create one more login page for staff Quote Link to comment https://forums.phpfreaks.com/topic/71538-solved-guys-i-nid-help-im-a-php-beginner/#findComment-360241 Share on other sites More sharing options...
MmmVomit Posted October 2, 2007 Share Posted October 2, 2007 What fields are there in the member table, and what fields are there in the staff table? Quote Link to comment https://forums.phpfreaks.com/topic/71538-solved-guys-i-nid-help-im-a-php-beginner/#findComment-360247 Share on other sites More sharing options...
aian04 Posted October 3, 2007 Author Share Posted October 3, 2007 ok maybe i gona create one more table for login process... tnx forur idea... Quote Link to comment https://forums.phpfreaks.com/topic/71538-solved-guys-i-nid-help-im-a-php-beginner/#findComment-360802 Share on other sites More sharing options...
aian04 Posted October 3, 2007 Author Share Posted October 3, 2007 <? $time = time() + 3600; setcookie("ID",$_POST['id'], $time); setcookie("pass",$_POST['password'], $time); ?> <html> <head> <link href="interface design/css.css" rel="stylesheet" type="text/css"></head> <body> <?php #connect to MySQL Server @mysql_pconnect('localhost', 'root', 'tmc') or die(mysql_error()); #connect to database @mysql_select_db('tgp') or die(mysql_error()); //if the login form is submitted // if form has been submitted // makes sure they filled it in if(!$_POST['id'] | !$_POST['password']) {?> <p class="error">Login Failed!<br>Please Type your Username and Password agian!</p> <?php} // checks it against the database $query = mysql_query("SELECT * FROM login WHERE id = '".$_POST['id']."'")or die(mysql_error()); //Gives error if user dosen't exist $row = mysql_num_rows($query); if ($row == 0) {?> <p class="error">Unauthorized Personnel</p> <? print "fuck";} while($list = mysql_fetch_array( $query )) { //gives error if the password is wrong if ($_POST['password'] != $list['password']) {?> <script>window.location ="login2.html"</script> <?} else { if ($list['userlevel'] == "admin"){ ?> <script> window.location="interface design/home.html" </script> <?php } else if($list['userlevel'] == "staff"){ ?> <script>window.location = "interface design/room.html";</script> <?} else if($list['userlevel'] == "user"){ ?> <script>window.location = "interface design/member.php";</script> <?} } } ?> ok now im workin wif one table.. its not workin... any suggestion guys.. i got 3 column in my login table id password and userlevel Quote Link to comment https://forums.phpfreaks.com/topic/71538-solved-guys-i-nid-help-im-a-php-beginner/#findComment-360865 Share on other sites More sharing options...
MadTechie Posted October 3, 2007 Share Posted October 3, 2007 Please use the code tag (#) button or [.code] [/.code] (no dot) Not working, doesn't help.. what doesn't work? what about a simple approach <?php $time = time() + 3600; setcookie("ID",$_POST['id'], $time); setcookie("pass",$_POST['password'], $time); ?> <html> <head> <link href="interface design/css.css" rel="stylesheet" type="text/css"></head> <body> <?php #connect to MySQL Server @mysql_pconnect('localhost', 'root', 'tmc') or die(mysql_error()); #connect to database @mysql_select_db('tgp') or die(mysql_error()); //if the login form is submitted // if form has been submitted // makes sure they filled it in if(isset($_POST['id']) && isset($_POST['password'])) { // checks it against the database //need to add a filter here $pass = $_POST['password']; $id = $_POST['id']; $query = mysql_query("SELECT * FROM login WHERE id = '$id' AND password = '$pass'")or die(mysql_error()); //Gives error if user dosen't exist $row = mysql_num_rows($query); if ($row == 0) { ?> <p class="error">Unauthorized Personnel</p> <?php print "Oppps";} }else{ $user = mysql_fetch_array( $query ); echo "<script>"; switch(strtolower($user['userlevel'])) { default: $page = "login2.html"; break; case "admin": $page = "interface design/home.html"; break; case "staff": $page = "interface design/room.html"; break; case "user": $page = "interface design/member.html"; break; } echo " window.location=\"$page\""; echo "</script>"; } }else{ ?> <p class="error">Login Failed!<br>Please Type your Username and Password agian!</p> <?php } ?> //untested Quote Link to comment https://forums.phpfreaks.com/topic/71538-solved-guys-i-nid-help-im-a-php-beginner/#findComment-360921 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.