-2

I am a beginner with PHP coding. I am working on a website for a Salon and the site has a form where users can book appointments in the form of sending an email and i am trying to POST values from multiple select boxes i have in the HTML form and sending that data along with the other fields in an email. The other fields are POST-ing fine. But the select boxes are not working. Below is the code i'm working with:

<?php
$clnt_name = $_POST['w_p_c_name'];
$clnt_email = $_POST['w_p_c_email'];
$clnt_phn_no = $_POST['w_p_c_number'];
$rsrvtn_date = $_POST['w_p_c_date'];
$hair_cut = $POST['opt_hair_cut'];
$colr_whl_hair = $POST['opt_colouring_whole_hair'];
$colr_retouch = $POST['opt_colouring_retouch_roots'];
$colr_highlight = $POST['opt_colouring_highlighting'];
$rebonding = $POST['opt_rebonding'];
$relax_straight = $POST['opt_relaxing_straightening'];
$perming = $POST['opt_perming'];
$threading = $POST['opt_threading'];
$bleaching = $POST['opt_bleaching'];
$manicure = $POST['opt_manicure'];
$pedicure = $POST['opt_pedicure'];
$nail = $POST['opt_nail'];
$gel_nail = $POST['opt_gel_nail'];
$massage = $POST['opt_massage'];
$scrub = $POST['opt_scrub'];
$wax_face = $POST['opt_wax_face'];
$wax_arms = $POST['opt_wax_arms'];
$wax_leg = $POST['opt_wax_leg'];
$wax_body = $POST['opt_wax_body'];
$wax_intimate = $POST['opt_wax_intimate'];
$makeup = $POST['opt_makeup'];
$hijab = $POST['opt_hijab'];
$hairstyle_blodry = $POST['opt_hairstyle_blowdry'];
$hairstyle_iron = $POST['opt_hairstyle_iron'];
$hairstyle_spcl = $POST['opt_hairstyle_special'];
$hair_trmnt = $POST['opt_hair_treatment'];
$face_cleaning = $POST['opt_face_cleaning'];
$facials = $POST['opt_facials'];
$face_trmnt = $POST['opt_face_treatments'];
$scrub_ladies = $POST['opt_scrubs_ladies'];
$massage_ladies = $POST['opt_massage_ladies'];

$data = "Name : ".$clnt_name."\nEmail : ".$clnt_email."\nPhone : ".$clnt_phn_no."\nRequested Date : ".$rsrvtn_date."\nServices Requested :\n\n".$hair_cut."\n".$colr_whl_hair."\n".$colr_retouch."\n".$colr_highlight."\n".$rebonding."\n".$relax_straight."\n".$perming."\n".$threading."\n".$bleaching."\n".$manicure."\n".$pedicure."\n".$nail."\n".$gel_nail."\n".$massage."\n".$scrub."\n".$wax_face."\n".$wax_arms."\n".$wax_leg."\n".$wax_body."\n".$wax_intimate."\n".$makeup."\n".$hijab."\n".$hairstyle_blodry."\n".$hairstyle_iron."\n".$hairstyle_spcl."\n".$hair_trmnt."\n".$face_cleaning."\n".$facials."\n".$face_trmnt."\n".$scrub_ladies."\n".$massage_ladies;

$file = "services.xlxs";

$subject = "Reservation Booking";
$mail_message1 = "Hi ".$clnt_name." We have received your request for a reservation with the following details.\n\n".$data."\n\nWe will be calling to confirm the reservation shortly.\n\nThank you";

$to_rsvtn = "[email protected]";
$subject2 = "Reservation";
$mail_message2 = "There has been a new request for a reservation. Details are listed below: \n\n".$data;


file_put_contents($file, $data1 . PHP_EOL, FILE_APPEND);
file_put_contents($file, $data2 . PHP_EOL, FILE_APPEND);
file_put_contents($file, $data3 . PHP_EOL, FILE_APPEND);

mail($clnt_email, $subject, $mail_message1, "From:" . $to_rsvtn);
mail($to_rsvtn, $subject2, $mail_message2, "From:" . $to_rsvtn);
header('Location: ba-complete.html');

 ?>

Any help is much appreciated.

3
  • 1
    Can you please post html code also ? Commented Jan 8, 2017 at 7:35
  • If a checkbox is not checked, the value is not sent. Your server needs to set the checkbox to value or empty depending on value passed or not Commented Jan 8, 2017 at 7:39
  • "The other fields are POST-ing fine." - I find that rather hard to believe, seeing many $POST which is invalid. Commented Jan 8, 2017 at 14:14

1 Answer 1

1

Adding the HTML code would indeed help.

If you want PHP to treat $_POST['select'] as an array of options just add square brackets to the name of the select element like this: <select name="select[]" multiple …

Then you can acces the array in your PHP script

<?php    
foreach ($_POST['select'] as $selectedOption) {
    echo $selectedOption."\n";
}
?>
Sign up to request clarification or add additional context in comments.

1 Comment

True, yet your answer failed to outline the use of many $POST's which is incorrect.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.