-1
ログインして情報にアクセスできるデータベース(学校プロジェクト、newbieはここ!)にリンクされたWebサイトを作成していますが、私がそれを変更するために何をしても、このエラーが発生し続ける。
解析エラー:行に/アプリケーション/ XAMPP/xamppfiles/htdocsに/ Unit1は/データベース/バンド・プロジェクト/ passCheck.php構文エラー、予期しない '$のユーザーID'(T_VARIABLE)38
passcheckのための私のコード.PHPは以下の通りです:
<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>
マイconfigページは次のとおりです。
<?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');
}
私のセッションPHPは次のとおりです。
<?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");
}
?>
私のホームページは次のとおりです。
<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>
ここで、userID変数は作成しますか? – ChrisBull
私は受け入れられた答えがここでの完全な解決であるとは思わない。 PDO APIに接続していることは明らかですが、mysqli_ APIを使用してセッションphpファイル内でクエリを実行することは明らかです。 'header( 'Location:http://localhost/Unit1/Databases/Band%20Project/homepage.php')にヘッダとエコーを使用することは言うまでもありません。 echo" Hello "。 $ firstname。 "" $ lastname; 'エコーは決して起こりません。この質問は、 'Parse error:syntax error、unexpected '$ userID'(T_VARIABLE)'というエラーメッセージに基づいて閉じられました。 –
上記の補足:* "エコー$エラー; ヘッダー( '場所:http://localhost/Unit1/Databases/Band%20Project/login.html')" * - エラーレポートが表示されるヘッダーの前に出力されていますあなたにそれについて語ったhttp://php.net/manual/en/function.error-reporting.php –