vendredi 10 mars 2017

how do I uncheck values from my database?

With my code here, if the user checks a check box beside one of the names the name gets saved into my review_shared table.

enter image description here

I'm trying to have my code so that if a box is unchecked, the name will be REMOVED from the review_shared table. Does you know how I can do this, or where I should start ? So, If Paul Thompson and/or Dan Frain are unchecked, they will be removed from my review_shared table.

    <?php
    //here we want to save the checked contacts to the review_shared table ;  that is,
    //who the user wants to share reviews with
    if(!empty($_POST['check_contacts'])) {
        foreach($_POST['check_contacts'] as $check) {

                    //$check="";
        //if the contact in review_shared is already checked, we don't want to save it multiple times
            $already_checked = "SELECT * from review_shared WHERE user_id = '$user_id' AND contact_id = '$check' AND review_id = " .$_GET['id'];

            $already_checked_result=mysqli_query($con,$already_checked);
            $num_rows = mysqli_num_rows($already_checked_result);

            if($num_rows >= 1) {
            echo "This is already a contact";
            }

        else if ($num_rows < 1) {

            //$_GET['id'] is the current review for which contacts are being edited, we are checking a contact to share that review with
                $insert_review_shared_command = "INSERT INTO review_shared VALUES(NULL," .$_GET['id']. ", '$user_id','$check')";

            //we want to save the checked contacts into the review_shared table
            $insert_into_review_shared_table = mysqli_query($con,$insert_review_shared_command);

        }

      }
   }

        $con->close();


        ?> 




Aucun commentaire:

Enregistrer un commentaire