我正在尝试向数据库中的表添加新行,表中只有两列,我正在使用表单来获取其中一个字段。这是我正在使用的表格
<form action="add_list.php" method="post">
Name: <input type="text" name="listname">
<input type="submit" value="Add List">
</form>
这里是 add_list.php
<?php
/* Execute a prepared statement by binding PHP variables */
$username = "mydb";
$password = "mydb";
$member = $_SESSION['SESS_MEMBER_ID'];
$listname = $_POST["listname"];
try {
$dbh = new PDO('mysql:;dbname=mydb', $username, $password);
$sth = $dbh->prepare('INSERT INTO lists VALUES (:member_id, :listname)');
$sth->execute(array(':member_id' => $member, ':listname' => $listname));
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();}
?>
我目前在第五行遇到错误
Undefined variable: _SESSION in /home/danu2_cj3/public_html/add_list.php on line 5
如何识别会话变量?
这是我设置会话的登录代码的一部分
if($result) {
if(mysql_num_rows($result) == 1) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['member_id'];
$_SESSION['SESS_FIRST_NAME'] = $member['firstname'];
$_SESSION['SESS_LAST_NAME'] = $member['lastname'];
session_write_close();
header("location: lists.php");
exit();
}else {
//Login failed
header("location: login-failed.php");
exit();
}