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  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>     <input name="health" type="checkbox" value="health"> health technician &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>     <input name="services[]" type="checkbox" value="ac"> air conditioning technician&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>     <input name="computer" id="computer" type="checkbox" value="computer"> computer technician&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>     <input name="services[]" type="checkbox" value="satelite"> satelite service technician&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>     <input name="services[]" type="checkbox" value="blacksmith"> blacksmith &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>     <input name="services[]" type="checkbox" value="aliminium"> aliminium technician &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>     <input name="services[]" type="checkbox" value="carpenter"> carpenter&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>     <input name="services[]" type="checkbox" value="housedecor"> interior designer & house decorations&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>     <input name="services[]" type="checkbox" value="gardener"> gardener&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>     <input name="services[]" type="checkbox" value="ceramics"> ceramics&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>     <input name="services[]" type="checkbox" value="painter"> painter&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -