php.whyme php.whyme - 14 days ago 4
SQL Question

Parse error: syntax error, unexpected '$userID' (T_VARIABLE) on line 38

I am creating a website linked to a database (school project, newbie here!) that would allow for one to login and access information, yet I keep on coming up with this error no matter what I do to change it.

Parse error: syntax error, unexpected '$userID' (T_VARIABLE) in /Applications/XAMPP/xamppfiles/htdocs/Unit1/Databases/Band Project/passCheck.php on line 38

My code for the passcheck.php is below:

<p>
<?php

$email = $_POST["email"];
echo $email;
echo "</br>";

$password = $_POST["password"];
echo $password;
echo "</br>";

require_once 'config.php';

require_once 'databaseclass.php';

$db = new databaseclass($pdo);


$sql = "SELECT * FROM User WHERE email = '" . $email . "' AND password = '" . $password . "'";
echo $sql;
echo "<br>";

$rows = $db->query($sql)->fetchAll();
$count = count($rows);
print_r($rows);
echo "<br>";
echo $count;

if($count == 1 ){
session_start();
$_SESSION['firstname'] = $firstname;
$_SESSION["lastname"] = $lastname;
$_SESSION['userID'] = $userID;
$_SESSION['loggedin'] = true;
header('Location:http://localhost/Unit1/Databases/Band%20Project/homepage.php');}
else{

session_destroy();
$error = "Your Login Name or Password is invalid";
header('Location:http://localhost/Unit1/Databases/Band%20Project/login.html');
echo $error;}

?>
</p>





My config page is:

<?php

$host = '127.0.0.1';
$db = 'bandProject';
$user = 'root';
$pass = '';
$charset = 'utf8';

try{wqcd
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
PDO::ATTR_EMULATE_PREPARES => false,
];

$pdo = new PDO($dsn, $user, $pass, $opt);
}
catch (PDOException $e)
{
exit('Error connecting to DataBase');

}


My session php is:

<?php
require_once 'config.php';
session_start();

$user_check = $_SESSION['userID'];


$ses_sql = mysqli_query($db,"select username from admin where username = '$user_check' ");

$row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC);

$login_session = $row['username'];

if(!isset($_SESSION['login_user'])){
header("location:http://localhost/Unit1/Databases/Band%20Project/login.html");
}
?>


My homepage is:

<h1><center><big><font color=#653C5E>Homepage</font></big></center></h1>
<BR>
<?php
require_once 'session.php' ;
if($count == 1 ){
session_start();
$_SESSION['firstname'] = $firstname;
$_SESSION['lastname'] = $lastname;
$_SESSION['userID'] = $userID;
$_SESSION['loggedin'] = true;
header('Location:http://localhost/Unit1/Databases/Band%20Project/homepage.php')
echo "Hello " . $firstname . " " . $lastname;}
//set all your session variables (firstname, lastname, userID)`
//should have from SQL results
//open homepage//
else{

session_destroy();
$error = "Your Login Name or Password is invalid";
echo $error;
header('Location:http://localhost/Unit1/Databases/Band%20Project/login.html');}

?>

<BR>
</BODY>



Answer

Try;

$_SESSION['userID'] = $rows["userID"];
Comments