Im trying to insert multiple checkbox values to mysql database in wordpress but its only inserting the last one I choose.
I have tried putting [] after Country but then it inserts only the word "Array"
<div class="container"> <form action="" method="post"> <input type="checkbox" id="Country" name="Country[]" value="India">India<br/> <input type="checkbox" id="Country" name="Country[]" value="USA">USA<br/> <input type="checkbox" id="Country" name="Country[]" value="Australia">Australia<br/> <input type="checkbox" id="Country" name="Country[]" value="Europe">Europe<br/> <input type="checkbox" id="Country" name="Country[]" value="Italy">Italy<br/> <br> <input type="submit" id="submit" name="submit132" value="Submit Values" class="btn btn-default"> </form> </div>
and here is the code from my functions.php file
if(isset($_POST['submit132'])) {
global $wbdb;
include ("yhteysEn.php");
$country = $_POST["Country"];
$sql2 = "INSERT INTO wp_checkbox (C_values) VALUES ('$country');";
try {
$kysely2 = $yhteys->prepare($sql2);
$kysely2->execute();
} catch (PDOException $e) {
die("VIRHE NRO 2: " . $e->getMessage());
}
}
I want to select multiple values from the checkbox and insert them to my db table like "India, USA, Italy"
Aucun commentaire:
Enregistrer un commentaire