0
我想向我的數據庫中的表中添加一個新行,表中只有兩列,並且我正在使用表單來獲取其中一個領域。這裏是我使用使用會話和PDO形式向mySQL添加一行
<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();
}
use session_start();在使用$ _SESSION之前。 – ncm
我已經試過,但它只是給我一個空白頁,並沒有將它添加到表 – Johnnerz