php - Writing multiple checkbox values to a database -
i'm trying write multiple checkbox values field in database seperated commas won't work. i'm using emplode , explode writes 1 of selected values. meaning if select 2 options, write one. here code below:
<?php ini_set('display_errors',1); ini_set('display_startup_errors',1); error_reporting(-1); session_start(); include_once '..../..php'; $emailtemp = $_post['email']; $ordernumber2 = substr($emailtemp, 0, 3); $ordernumber1 = rand(1,100); $ordernumber = $ordernumber2.$ordernumber1; error_reporting(e_all); ini_set('display_errors', '1'); $mysql_host = "localhost"; $mysql_username = ""; $mysql_password = ""; $mysql_database = ""; $services = implode(",",$_post["services"]); $mysqli = new mysqli($mysql_host, $mysql_username, $mysql_password, $mysql_database); $statement = $mysqli->prepare("insert guest_orders (streetaddress, floor, building, apartment, area, phone, block, avenue, ordernumber, email, service) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); $statement->bind_param('sssssssssss', $_post['streetaddress'], $_post['floor'], $_post['building'], $_post['apartment'], $_post['area'], $_post['phone'], $_post['block'], $_post['avenue'], $ordernumber, $_post['email'], $services); $results = $statement->execute(); if($results){ header('location:../thankyou.php'); }else{ header('location:../error.php'); } ?>
also, form:
<form method="post" action="includes/guestorder.php" name="guestform" id="guestform" autocomplete="off" onsubmit="return confirm('are sure of details entered?');"> <br> <center> please choose services require<br><br> <input name="services[]" type="checkbox" value="electrician" checked> electrician <br> <input name="health" type="checkbox" value="health"> health technician <br> <input name="services[]" type="checkbox" value="ac"> air conditioning technician <br> <input name="computer" id="computer" type="checkbox" value="computer"> computer technician <br> <input name="services[]" type="checkbox" value="satelite"> satelite service technician <br> <input name="services[]" type="checkbox" value="blacksmith"> blacksmith <br> <input name="services[]" type="checkbox" value="aliminium"> aliminium technician <br> <input name="services[]" type="checkbox" value="carpenter"> carpenter <br> <input name="services[]" type="checkbox" value="housedecor"> interior designer & house decorations <br> <input name="services[]" type="checkbox" value="gardener"> gardener <br> <input name="services[]" type="checkbox" value="ceramics"> ceramics <br> <input name="services[]" type="checkbox" value="painter"> painter <br> <?php echo "<br><fieldset>"; echo "<legend>your details & information</legend>"; echo "street address:<br /> <input name='streetaddress' id='streetaddress' type='text' required /><br />"; echo "building/house:<br /> <input name='building' id='building' type='text' required /><br />"; echo "avenue:<br /> <input name='avenue' id='avenue' type='text'><br />"; echo "block:<br /> <input name='block' id='block' type='text' required /><br />"; echo "floor:<br /> <input name='floor' id='floor' type='text'><br />"; echo "apartment:<br /> <input name='apartment' id='apartment' type='text'><br />"; echo "area:<br /> <input name='area' id='area' type='text' required /><br />"; echo "email address:<br /> <input name='email' id='email' type='text' pattern='[a-za-z0-9._%+-]+@[a-za-z0-9.-]+\.[a-za-z]{1,63}$' required /><br />"; echo "phone number:<br /> <input name='phone' id='phone' type='text' pattern='[569][0-9]{7}' required /><br />"; echo "</fieldset>"; ?> <br> <input type="submit" class="submit" id="submit" value="submit" /><input type="reset" value="reset"><br> </form>
use quotes $services '"'.$services.'"'
$statement->bind_param('sssssssssss', $_post['streetaddress'],$_post['floor'], $_post['building'], $_post['apartment'], $_post['area'], $_post['phone'], $_post['block'], $_post['avenue'], $ordernumber, $_post['email'], '"'.$services.'"');
Comments
Post a Comment