-2

Here is my error:

Parse error: syntax error, unexpected 'Connection' (T_STRING), expecting ',' or ';' in /home/ubuntu/workspace/login.php on line 13

The code:

<?php

// establishing the MySQLi connection
$con = mysqli_connect(“localhost”,”root”,””,”members”);

if (mysqli_connect_errno()) {
    echo “MySQLi Connection was not established:” .mysqli_connect_error();
}

// checking the user
if(isset($_POST[‘login’])) {
    $email = mysqli_real_escape_string($con,$_POST[’email’]);
    $pass = mysqli_real_escape_string($con,$_POST[‘pass’]);

    $sel_user = "select * from members where user_email='$email AND user_password='$pass'";

    $run_user = mysqli_query($con, $sel_user);
    $check_user = mysqli_num_rows($run_user);

    if($check_user > 0) {
        $_SESSION[‘user_email’] = $email;
        echo “<script>window.open(‘home.php’,’_self’)</script>”;
    } else {
        echo “<script>alert(‘Email or password is not correct, try again!’)</script>”;
    }
}

?>
halfer
  • 19,824
  • 17
  • 99
  • 186
Daniel Murran
  • 95
  • 2
  • 2
  • 7

1 Answers1

4

It looks like you're using oblique quotes ( and ) rather than straight ones (" and '). Amend those to the ones PHP requires and you'll be fine. This is often a result of using an inappropriate editor, such as a word processing package; for example Microsoft Word replaces straight quotes with oblique quotes using a feature called "Smart Quotes".

Note that double quotes and single quotes have slightly different behaviours in PHP. With single quotes, the difference is that they do not understand control characters (e.g. \n) and they do not interpolate inline variables.


Incidentally you have two issues here:

$sel_user = "select * from members where user_email='$email  AND user_password='$pass'";

Your email string is not quoted on both sides, so this will result in a SQL error. Also, you're storing passwords in plaintext - they should be hashed and salted. See the PHP manual for how to do this in a secure fashion.

halfer
  • 19,824
  • 17
  • 99
  • 186