lundi 17 juin 2019

How to insert information to users profile based on a checkbox input?

To save a users input to their profile via checkbox input.

I'd like to have a user to be able to select multiple check boxes from a list of items. Then that information will save to their personal profile for them to view their personal page. I'd like it to update automatically with out the user having to press a submit button.

I do have a user database created that stores all the users information. However, I do not know how I can insert the information into the database if they check or uncheck a box.

$sql = "SELECT color, name, grade FROM leadRoutes";``
$result = $conn->query($sql);

 if ($result->num_rows > 0) {
     echo "<table>
        <tr>
        <th>Color</th>
        <th>Name</th>
        <th>Grade</th>
        </tr>";
        while($row = $result->fetch_assoc()) {
            echo "<tr><td>".$row["color"]."</td>
                      <td>".$row["name"]."</td>
                      <td><input type='checkbox' name='grade[]' value='grade'>".$row["grade"]."</td>
                      </tr>";
        }
        echo "</table>";
    } else {
        echo "0 results";
    }
    if ( isset($_GET['grade']) && is_array($_GET['grade']) ) { foreach ( $_GET['keyword'] as $v ) {

    }
}

My expected result is for the user to select a checkbox from a page that has a list. Once that checkbox has been selected it will automatically send that data into the users profile, so when they click on their personal page it will display the list of checkboxes they selected.




Aucun commentaire:

Enregistrer un commentaire