jeudi 5 janvier 2017

How to insert multiple checkbox values to database?

I have the following piece of code inside a html form tag :

<label for="client">Services Included:</label>
    <p><input type="checkbox" name="service[]" value="Spa"> Spa </p>
    <p><input type="checkbox" name="service[]" value="Massage"> Massage </p>
    <p></p>
    <input type="submit" value="Submit" />

And in the php code I have this:

      if(!empty($_POST['service']))
  {
    foreach ($_POST['service'] as $selected) 
    {
      $query7 ="INSERT INTO reservation_includes_service VALUES (3,'".$selected."');";
      $queryexe7 = mysql_query($queryexe7);

    }
  }

Although I have tried everything, the query doesn't work... Any ideas? Thank you for your help :)




Aucun commentaire:

Enregistrer un commentaire