freddyw Posted September 4, 2009 Share Posted September 4, 2009 Hi. Im having trouble gettin my log in to authenticate. I've been going over it racking my head and i cant see why. I have the log in form in HTML which i cant see there would be a problem there <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <meta name="author" content="Fred!" /> <title>Log in</title> </head> <body></body> <FONT FACE="Arial, Helvetica, Geneva"> Please enter your user log in details here...<br><br> <form action = "authenticate.php" method = "post"> Username: <br> <input type = "text" name = "username"> <br><br> Password: <br> <input type = "password" name = "password"> <br><br> <input type = "submit" value = "Log In"> </form> </font> </body> </html> The problem is in the authenticate.php <?php ini_set("display_errors","2"); ERROR_REPORTING(E_ALL); //include("header.php"); //can we use mysql? if(!function_exists('mysql_connect')) die("MySQL extension not enabled"); //connect to mysql server $conn =@mysql_pconnect('************', '*********', '*******') or die(mysql_error()); mysql_select_db('b11_4059953_db1') or die(mysql_error()); //find our script name $script = $_SERVER['PHP_SELF']; $referer = $_SERVER ['HTTP_REFERER'] $username = (isset($_POST['username'])) ? mysql_real_escape_string($_POST['username']) : ''; $password = (isset($_POST['password'])) ? mysql_real_escape_string($_POST['password']) : ''; //if either form is empty return to login if ((!$username) or(!$password)) { header ("Location:$referer"); exit(); } //create query $sql="select * from users where username =\"$username\" and password =\"$password\""; //execute the query $rs = mysql_query ($sql, $conn) or die ("could not execute query") //get number of rows $num = mysql_numrows ( $rs ); //log in if match if ($num !=0) { $msg = "Welcome $username - you are logged in"; } else { header ("Location:$referer"); exit(); } ?> <html> <head> <title> Logged in </title> </head> <body> <?php echo ( $msg ); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/173152-solved-log-in-problem/ Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 What exactly is happening, versus what you're expecting to happen? Is it producing error messages? Quote Link to comment https://forums.phpfreaks.com/topic/173152-solved-log-in-problem/#findComment-912665 Share on other sites More sharing options...
freddyw Posted September 4, 2009 Author Share Posted September 4, 2009 there is no error messages. im expecting "welcome (user) you are logged in" and im getting a blank page after hitting the submit button Quote Link to comment https://forums.phpfreaks.com/topic/173152-solved-log-in-problem/#findComment-912668 Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 Place checkpoints in your code. Every few lines, do something like this: echo('Got past the first if/else<br />'); Then maybe later in your code: echo('Got past variable naming<br />'); It will help you figure out what the code is doing. Make one at the top of your code too, just to make sure you know that your code started correctly, without parse errors. Quote Link to comment https://forums.phpfreaks.com/topic/173152-solved-log-in-problem/#findComment-912670 Share on other sites More sharing options...
PFMaBiSmAd Posted September 4, 2009 Share Posted September 4, 2009 The posted code contains a fatal parse error due to a missing ; - Parse error: parse error in your_file.php on line 18 Simply put, to avoid wasting your time on simple problems, you have got to learn php, develop php code, and debug php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini (setting these in your code won't show fatal parse errors.) Stop and start your web server to get any change made to php.ini to take effect and confirm that the settings were actually changed using a phpinfo() statement. Quote Link to comment https://forums.phpfreaks.com/topic/173152-solved-log-in-problem/#findComment-912679 Share on other sites More sharing options...
freddyw Posted September 4, 2009 Author Share Posted September 4, 2009 Thanks. Im in education, learning php. When i return to university in october i'll be in my final year. ive set up a website just to practice my php and set challanges for myself. I know it may seem redundant asking you for the answers. However, if i see where my code goes wrong, and someone points out why, im still improving, and hopefuly wont repeat that mistake in the future. Cannot believe i missed that semicolon. ive rectified it and im still getting the same problem. Quote Link to comment https://forums.phpfreaks.com/topic/173152-solved-log-in-problem/#findComment-912687 Share on other sites More sharing options...
PFMaBiSmAd Posted September 4, 2009 Share Posted September 4, 2009 Same error for the same reason later in the code (near line 39.) Did I mention how much time you will waste by not having those two settings as suggested. Quote Link to comment https://forums.phpfreaks.com/topic/173152-solved-log-in-problem/#findComment-912688 Share on other sites More sharing options...
freddyw Posted September 4, 2009 Author Share Posted September 4, 2009 i saw the error on line 39, (40). and fixed it. i have this at the beginning of my code ini_set('display_errors',1); error_reporting(E_ALL|E_STRICT); so why is it not displaying the errors. please bare in mind, im new to PHP Quote Link to comment https://forums.phpfreaks.com/topic/173152-solved-log-in-problem/#findComment-912691 Share on other sites More sharing options...
PFMaBiSmAd Posted September 4, 2009 Share Posted September 4, 2009 (setting these in your code won't show fatal parse errors.) Because your code never reaches the execution phase if an error occurs during the parse phase. Quote Link to comment https://forums.phpfreaks.com/topic/173152-solved-log-in-problem/#findComment-912692 Share on other sites More sharing options...
freddyw Posted September 4, 2009 Author Share Posted September 4, 2009 so how do i make it so i can get the errors? Quote Link to comment https://forums.phpfreaks.com/topic/173152-solved-log-in-problem/#findComment-912708 Share on other sites More sharing options...
bundyxc Posted September 4, 2009 Share Posted September 4, 2009 PFMaBiSmAd already answered that question. The posted code contains a fatal parse error due to a missing ; - Parse error: parse error in your_file.php on line 18 Simply put, to avoid wasting your time on simple problems, you have got to learn php, develop php code, and debug php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini (setting these in your code won't show fatal parse errors.) Stop and start your web server to get any change made to php.ini to take effect and confirm that the settings were actually changed using a phpinfo() statement. Quote Link to comment https://forums.phpfreaks.com/topic/173152-solved-log-in-problem/#findComment-912721 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.