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...

  //for a user to follow a thread
        $fv = $_POST['folVal'];
            //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";
        } 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']}'";
            $q = "DELETE FROM tUserFavourites WHERE ThreadID='$TID' AND Username='$UID'";
            if(mysql_affected_rows() >0) {
                echo "true";
            } else {
            echo "false";
4 Years
Discussion Span
Last Post by iamthwee

In your code you have $q declared in line 19 and 22, the first query statement will be overwrited by the second and only this last will be performed by mysql_query.

At line 23 add or die(mysql_error()); to see if there is an error.

Also change $r.mysql_close(); with mysql_close(); or add as first argument the link identifier, not the query variable: http://php.net/manual/en/function.mysql-close.php

Edited by cereal


Thanks all...

found the prob..

for some reason php is not recognising the else test for $fv... with your updated SQL manishanibhwani... thanks

just got more explcit - ie $fv must equal a specific value in the else and bingo it worked

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.