Got a problem that has completely stumped me... am hoping the combined wisdom of the forum could assist...
I have a php script that enables a user to follow and unfollow items on a site...
Am doing this with a table that captures basically the user's id and the item id...
The below code is what does all the dirty work...
Writing a new record to the db when a user elects to follow an item works fine... However for some reason the delete request does not want to work when a user elects to "unfollow" an item...
Would appreciate any suggestions/tips... A couple of notes, does not appear to be any issues with db connection or privilleges (have set it to full access for the user). And in any case the fact that I can write a new record for new "follows" demonstrates that db connectivity is not the issue...
THE CODE --->
//for a user to follow a thread
if(!empty($_POST['folVal'])){
$fv = $_POST['folVal'];
if($fv==1){
//user has selected the item to be followed, so need to update UserFavourites table
$q = "INSERT INTO tUserFavourites (ThreadID, Username ) VALUES ('{$_POST['ThreadID']}','{$_POST['Username']}')";
$r = mysql_query($q);
if(mysql_affected_rows() == 1) {
//echo $fv;
echo "true";
} else {
echo "false";
}
$r.mysql_close();
} else
{
//user has selected the item to be UNfollowed, so need to update UserFavourites table
$q = "DELETE FROM tUserFavourites WHERE ThreadID='{$_POST['ThreadID']}' AND Username='{$_POST['Username']}'";
$TID=$_POST['ThreadID'];
$UID=$_POST['Username'];
$q = "DELETE FROM tUserFavourites WHERE ThreadID='$TID' AND Username='$UID'";
mysql_query($q);
if(mysql_affected_rows() >0) {
echo "true";
} else {
echo "false";
}
$r.mysql_close();
}
}