mardi 24 février 2015

insert multiple checkbox value in mysql using php?

I'm trying to insert multiple checkbox values into mysql database USING PHP.


however, my code doesn't insert everything apart from the checkboxes values into the mysql database!


My code is this:



if (isset($_POST['product_name'])) {
include "config/connect.php";
$product_name = mysqli_real_escape_string($db_conx, $_POST['product_name']);
$sizez = implode(',', mysqli_real_escape_string($db_conx, $_POST['sizez']));


$stmt = mysqli_prepare(
$db_conx,
"INSERT INTO `$storeShop` (`product_name`, `sizez`) VALUES (?, ?)"
);
//after validation, of course
mysqli_stmt_bind_param($stmt, "ss", $product_name, $sizez);


if (mysqli_affected_rows($db_conx))
{
mysqli_stmt_close($stmt);//<-- CLEAN UP AFTER YOURSELF!
//update was successful
$id = mysqli_insert_id($db_conx);
}

mysqli_stmt_close($stmt);
}


and this is my HTML code:



<input type="checkbox" name="sizez[]" class="sizes" value="small">
<input type="checkbox" name="sizez[]" class="sizes" value="medium">
<input type="checkbox" name="sizez[]" class="sizes" value="large">


is there anything that I missing?


any advise would be appreciated.





Aucun commentaire:

Enregistrer un commentaire