Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/173152-solved-log-in-problem/
Share on other sites

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.

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.

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.

 

:confused:

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.