I made a list of checkboxes that upon click would be sent to database. Every time I submit data the value is 0. If I try and convert the value of the array to string, I get string to array error.

<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) {
         // this enters in the value as 0 idk why
        $wpdb->query("INSERT INTO A(Product1) VALUES('$id');");


<button name="btn">Submit</button>
  • 1
    is there code missing from this question? Where is the code located? Can you include the error messages too? How are you testing the values?
    – Tom J Nowell
    Apr 26, 2023 at 21:43

1 Answer 1


You didn't include value in your checkboxes you have:

'<input type="checkbox" name="Num1[]" />' . $Thing1->Product1 . "<br />";

Should be:

'<input type="checkbox" name="Num1[]" value="' . $Thing1->Product1 . '" />' . $Thing1->Product1 . "<br />";

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.