jeudi 19 janvier 2017

How do I echo my checked checkboxes?

I have names in my database like below...

enter image description here

With the code below I see these users on my page with a checkbox beside them.

 $select_from_user_table = "SELECT  contacts.contact_id, user.username
FROM contacts 
INNER JOIN user
ON contacts.contact_id=user.user_id WHERE contacts.user_id = '$user_id'";

    //get the result of the above
    $result2=mysqli_query($con,$select_from_user_table); 
    //show the usernames, phone numbers
    while($row = mysqli_fetch_assoc($result2)) {
    echo "<input type='checkbox' name='check_contacts[]' >" . $row['username'] . "<br>";


if(!empty($_POST['check_contacts'])) {
    foreach($_POST['check_contacts'] as $check) {
            echo $check; //echoes the value set in the HTML form for each checked checkbox.
                         //so, if I were to check 1, 3, and 5 it would echo value 1, value 3, value 5.
                         //in your case, it would echo whatever $row['Report ID'] is equivalent to.
    }
}
    }
    $con->close(); 

How can I have it so when the checkboxes are checked, the result will be echoed like Will Shakespeare John Grisham if those names are checked ? I would have thought in the input type part I would simply have put

value=" $row['username'] " 

but it doesn't work.

Aucun commentaire:

Enregistrer un commentaire