Basic Login Code


#1

Hi all I am just starting out with php and trying to get a basic login system to work. I have a database called sales and a table called users. The table contains fields called First_Name, Surname, Email, Password.

I have a basic html form called loginform.html

[code]

Login Form

Login Form

Username:

Password:

[/code]

Then I have a php script as follows:

[php]<?php

if ((!isset($_POST[“username”])) || (!isset($_POST[“password”]))){
header(“Location: loginform.html”);
exit;
}

$mysqli = mysqli_connect(“localhost”, “root”, “”, “sales”);

$sql = “SELECT First_Name, Surname FROM users WHERE
Email = '”.$_POST[“username”]."’ AND
Password = ‘".$_POST[“password”]."’;
$result = mysqli_query($mysqli, $sql) or die(mysqli_error($mysqli));

if (mysqli_num_rows($result) == 1) {

while ($info = mysqli_fetch_array($result)){

$First_Name = $info[‘First_Name’];
$Surname = $info[‘Surname’];
}

setcookie(“auth”, “1”, 0, “/”, “localhost”, 0);

$display_block = "

".$First_Name". ".$Surname." is logged in.

You are logged in.

Logged In

"; } else {

header(“Location: loginform.html”);
exit;
}
?>

User Login <?php echo "$display_block"; ?> [/php]

The error message is:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\wamp\www\userlogin.php on line 19

I am sure this is something very basic or a missed bracket but I can’t spot it, any help would be greatfully appreciated.

Thanks in advance


#2

the problem is the query. you’re missing the last double quote.
[php]
$sql = “SELECT First_Name, Surname FROM users WHERE Email = '”.$_POST[“username”]."’ AND Password = ‘".$_POST[“password”]."’";[/php]


#3

Thanks very much, knew it would be something like that just couldn’t spot it