我在PHP有一個網站。當登錄用戶訪問我網站上的特定網頁時,我嘗試將會話變量$_SESSION['user_name']
存儲到mysql數據庫。php store會話變量在mysql數據庫中
<?php
$servername = "localhost";
$username = "user1";
$password = "user1";
$dbname = "payment";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = 'INSERT INTO users
VALUES ('.$_SESSION['user_name'].')';
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
錯誤消息:
說明:未定義變量:_SESSION在/opt/lampp/htdocs/succes.php第16行
嘗試了一串東西,但可以」弄明白了。這裏有什麼問題?
1.你在哪裏開始您的會話發現了什麼? 2.請參閱:http://stackoverflow.com/q/11321491/3933332 – Rizier123