2
I have the following code that records in the database the id of an article that the user "liked".
$sql = "INSERT INTO favoritos (id_user, id_oferta)
VALUES ('$login_session', '$id')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
The way I have the code the user can like the same article as many times as he wants.
How can I resolve this situation?
If your table is Mysql, create a unique index with the id_user and id_offer fields or before doing the Insert, select and check if you returned any results, if yes, do not update.
– Filipe Moraes