I have a server script with which i have allowed the user to mark any item as favorite, but i also want another script through which the user can unfavorite the same item if they want and that item should be deleted from their favorite list. I have kept the same table for both favorite and unfavorite code, therefore i have used update query to update the details. For this purpose i have a code, but its not working, as i am new in the programming field would appreciate some guidance
<?php
require_once('config.php');
$favorite = $_REQUEST['favorite'];
$unfavorite = $_REQUEST['unfavorite'];
$id=$_REQUEST['id'];
$unfavoritedeal=mysql_query("SELECT * FROM favoritedeals where id='".$id."'"); //favoritedeals is the name of the table
if($row=mysql_fetch_array($unfavoritedeal))
{
$favorite=$row['favorite'];
$unfavorite=$row['unfavorite'];
}
$myfavorite=(isset($_REQUEST['favorite'])?$_REQUEST['favorite']:$favorite);
$myunfavorite=(isset($_REQUEST['unfavorite'])?$_REQUEST['unfavorite']:$unfavorite);
$update = mysql_query("update favoritedeals set favorite = '".$myfavorite."', unfavorite = 1 where id = '".$id."'");
if(unfavorite="1" where id='".$id."')
{
"delete from favoritedeals WHERE id= '".$id."'";
}
$posts[0]['message'] = 'favorite list updated';
$selectt = mysql_query("select * from favoritedeals where id = '".$id."'");
$results = mysql_fetch_assoc($selectt);
$posts[0]['detail'] = $results;
header('Content-type: application/json');
echo json_encode($posts);
?>