我创建了一个脚本,用于在SESSION中的用户在数据库中添加新数据, 但有些事情是错的...... 请看看。
我试图完成这个脚本但是......
user_id .... ... ... ...........
0 | dsadadsa | sadsadsa |asdsad |2017-02-04 01:32:26
user_id仍然在0 ...并且应该添加用户的ID ...
有人可以帮我解决这个问题......我真的需要把他弄好。
members:
username | id | password | ...
sessions:
id | user_id | name | ...
||||||||||||||||||||||||||||||||||||
<?php
require "loginheader.php";
$host = 'localhost';
$dbname = 'db_movie';
$username = 'root';
$password = '';
$nam = mysql_real_escape_string($_POST['name']);
$se = mysql_real_escape_string($_POST['sess']);
$ep = mysql_real_escape_string($_POST['episode']);
$userID = $_SESSION['username'];
// Creating...
$conn = new mysqli($host, $username, $password, $dbname);
// Checking connecton...
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//Inserting...
$sql = "INSERT INTO sessions (name, user_id, sess, episode, date) VALUES ('$nam', '$userID', '$se', '$ep', NOW())";
if ($conn->query($sql) === TRUE) {
echo " You added $nam in to your <a href='../series.php'>Library</a>.";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>