I made a list of checkboxes that upon click get sent to a database. However, the only values that show in the database are 0. For example, a person can click 2 checkboxes, but the values sent to the database are 0 and 0. How can I submit the real values of the elements to the database?

Here is my code:

<form method="post">
    global $wpdb;
    $Result = $wpdb->get_results("SELECT Product1 FROM A");
    foreach($Result as $Thing1) {
        echo '<input type="checkbox" name="Num1[]" />' . $Thing1->Product1 . "<br />";
        $Age = $_POST['Num1'];

    if($_POST['btn']) {
        if(!empty($Age)) {
            foreach($Age as $id) {
                $Word = $id;
            // does not matter if checkbox value is 1 or 4, still goes as 0 to db
            $wpdb->query("INSERT INTO A(Product1) VALUES('$Word');");


    <input type="submit" name="btn" />    
  • I Got it! I just needed to add value to my input box to value= $Thing1->Product1
    – John Lyons
    Apr 27, 2023 at 15:30


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.