Tiff Posted February 10, 2007 Share Posted February 10, 2007 Ive been working on a login session for my college work, but i have one problem, it doesnt work, i was wondering if anyone could help me with it, i will post my code below, and if you could reply and tell me what you think is wrong with it then i would be more than greatfull <?php error_reporting(E_ALL); if (!isset($FirstName) || !isset($Password)) { header( "Location: index.htm" ); } else if (empty($FirstName) || empty($Password)) { header( "Location: index.htm" ); } else { $user = ($_POST['FirstName']); $pass = ($_POST['Password']); $host="localhost"; $db_user="chris_root"; $db_password="?"; $database="chris_mydb"; $db = mysql_connect("localhost","chris_root","?") or die ("Error connecting to database."); mysql_select_db("chris_mydb", $db) or die ("Couldn't select the database."); $result=mysql_query("select * from person where FirstName='$user' AND Password='$pass'", $db); $rowCheck = mysql_num_rows($result); if($rowCheck > 0){ while($row = mysql_fetch_array($result)){ session_start(); session_register('FirstName'); header( "Location: Template.php" ); } } else { header( "Location: index.htm" ); } } ?> Thanks Chris Quote Link to comment Share on other sites More sharing options...
papaface Posted February 10, 2007 Share Posted February 10, 2007 Please explain more. What do you mean by it doesnt work? For a start this: <?PHP error_reporting(E_ALL); if (!isset($FirstName) || !isset($Password)) { header( "Location: index.htm" ); } else if (empty($FirstName) || empty($Password)) { header( "Location: index.htm" ); } isnt correct because the else doesnt have { } Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 10, 2007 Author Share Posted February 10, 2007 Well i when you login, i think it runs the PHP script and then just goes back to the Index page, if you get me Try it http://www.chris.orangemanta.co.uk use: Firstname: Luke Password: orange Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 10, 2007 Author Share Posted February 10, 2007 Hey i would just like to add When you said the else is missing the {} Its now come up with an error now i have added them Parse error: syntax error, unexpected T_ELSE in /home/chris/public_html/userlogin.php on line 16 Im all new to PHP and what not Thanks if you can help <?PHP error_reporting(E_ALL); if (!isset($FirstName) || !isset($Password[/color)) { header( "Location: index.htm" ); } else{ if (empty($FirstName) || empty($Password)) { header( "Location: index.htm" ); } } Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 10, 2007 Author Share Posted February 10, 2007 I've sorted the original problem you told me about and now it isnt doing much more than it was the first time <?PHP error_reporting(E_ALL); if (empty($FirstName) || empty($Password)) { header( "Location: index.htm" ); } else{ if (!isset($FirstName) || !isset($Password)) { header( "Location: index.htm" ); } $user = ($_POST['FirstName']); $pass = ($_POST['Password']); $host="localhost"; $db_user="chris_root"; $db_password="?"; $database="chris_mydb"; $db = mysql_connect("localhost","chris_root","?") or die ("Error connecting to database."); mysql_select_db("chris_mydb", $db) or die ("Couldn't select the database."); $result=mysql_query("select * from person where FirstName='$user' AND Password='$pass'", $db); $rowCheck = mysql_num_rows($result); if($rowCheck > 0){ while($row = mysql_fetch_array($result)){ session_start(); session_register('FirstName'); header( "Location: Template.php" ); } } else { header( "Location: index.htm" ); } } ?> Quote Link to comment Share on other sites More sharing options...
Hypnos Posted February 10, 2007 Share Posted February 10, 2007 It's hard to debug a script that is redirecting instantly, if you don't remove the redirect to check for warnings. <?php error_reporting(E_ALL); if (empty($FirstName) || empty($Password) || !isset($FirstName) || !isset($Password)) { echo "I would of sent you back to login, because you forgot to type something."; //header( "Location: index.htm" ); } else{ $user = ($_POST['FirstName']); $pass = ($_POST['Password']); $db = mysql_connect("localhost","chris_root","?") or die ("Error connecting to database."); mysql_select_db("chris_mydb", $db) or die ("Couldn't select the database."); $result=mysql_query("select * from person where FirstName='$user' AND Password='$pass'", $db); $rowCheck = mysql_num_rows($result); if($rowCheck > 0){ session_start(); session_register('FirstName'); echo "Login correct. I would of loaded Template.php"; //header( "Location: Template.php" ); } else { echo "Invalid login."; //header( "Location: index.htm" ); } } I also cleaned up some redudancy and whitespace. Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 10, 2007 Author Share Posted February 10, 2007 It now says that i have something missing. I dont know what it is, but the method on the index page is "POST" Should it be something else? Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 10, 2007 Author Share Posted February 10, 2007 I would also like to ask: I masked the password with the HTML code: <input type="password" name="Password" mask="x"> Would this bother the PHP code in anyway when trying to read it? Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 11, 2007 Author Share Posted February 11, 2007 Ok i still have the same prblem and it is starting to get a bit tedious, if you get me If anyone could help i will love you forever Quote Link to comment Share on other sites More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 For starters, you do not need a loop if your only expecting one record. Secondly, session_register() has long been depricated. Thirdly, you never assign anything to any session variable (log user in). Change this.... if($rowCheck > 0){ while($row = mysql_fetch_array($result)){ session_start(); session_register('FirstName'); header( "Location: Template.php" ); } } else { header( "Location: index.htm" ); } } to.... if ($rowCheck > 0) { $row = mysql_fetch_array($result); session_start(); $_SESSION['FirstName'] = $user; header( "Location: Template.php" ); } else { header( "Location: index.htm" ); } Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 11, 2007 Author Share Posted February 11, 2007 ok thanks, but i still have the same problem, and i cant work it out ever get something like that? its gets on your nerves doesnt it, anyway lets explain it; You input your firstname and your password into the Index page after you have signed up, and then you click the login button, and as i have had some help they made it so it tells me that theres something missing instead of instantly redirecting me, so it keeps saying that i forgot to put something either in the "FirstName" or "Password" box if you get me.. But anyway, its added the user and the file to the data base but it just tells me that theres something missing, so i dont know what to do, are there any helpful suggestions you can think of that might help? Quote Link to comment Share on other sites More sharing options...
trq Posted February 11, 2007 Share Posted February 11, 2007 Post your current code. Quote Link to comment Share on other sites More sharing options...
Tiff Posted February 11, 2007 Author Share Posted February 11, 2007 Eep ive solved the problem, i dont know how, but its all working now, thanks for all your help! =] Thank you! Quote Link to comment 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.