I am trying to create a login page where I have to link my database to the PHP code along with SQL query. I am using a SELECT and WHERE statement to assign the variable to the code, but it gives me a syntax error because I cannot concatenate the variables. Here's the code and please help me out.
$login = trim($_POST["id"]);
$password = trim($_POST["pass"]);
$conn = db_connect();
$sql = "SELECT first_name, last_name, email_address, last_access FROM
users WHERE id = '".$login."' AND password = '".$password."'";
$results = pg_query($conn, $sql);
if(pg_num_rows($results))
{
//not zero means something was found
//user found, use pg_fetch_result to pull user specific info to display
pg_fetch_result($results);
}
else
{
//user not found, check for just login id
$sql = "SELECT * FROM users WHERE id = '".$login."'";
$results = pg_query($conn, $sql);
if(!pg_num_rows($results))
{ //user not found, empty $login to unstick it
$login = ""; //when echo’’ed in the form
}
}
?>
I can also show you a snip where the AND password part is showing in green color which means it is getting inside the double quotes and not working as an inbuilt function.