Basic Login Code


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


Login Form

Login Form




Then I have a php script as follows:


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

$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”);

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


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


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