这个问题与that question
不同我目前正在为我的网站开发一个注册/登录系统的解决方案,我想要做的是,表'member'的每个用户在数据库中都有一个'favorites'字段,它会选择元素它希望通过addfav.php文件放入收藏夹,该文件在用户的字段“收藏夹”中添加,即在网站上选择的元素的ID。 当您单击“添加到收藏夹”时,它会执行addfav.php(该文件通过URL检索元素的ID):
<?php
session_start();
$_SESSION['user'] = $user_name;
if (!isset($_SESSION['login'])) {
header ('Location: login.php');
}
$servername = "";
$username = "";
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$id = $_GET['id'];
if (empty($id)) {
echo "Erreur";
}
else {
// sql to delete a record
$sql = "UPDATE 'members' SET 'favorite' = ".$id." WHERE 'user' = ".$user_name."";
if ($conn->query($sql) === TRUE) {
header('Location: allmovie.php');
} else {
echo "Error deleting record: " . $conn->error;
}
$conn->close();
}
?>
但它不起作用......