This question is different of that question
I am currently developing a solution for my site for a registration / login system, which I would like to do either that each user of the table 'members' has a 'favorites' field in the database, It will select the elements it wishes to put in favorites thanks to an addfav.php file, which adds in the field 'favorites' of the user, the id of the element selected on the site. When you click on "Add to favorites" it executes addfav.php (the file retrieves the id of the element by the URL):
<?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();
}
?>
But it does not work ...