0

I'm trying to get that from a dropdown list from my html.

<FORM ID="" ACTION="save.php">
            <TABLE BORDER=1 WIDTH=90%>
                    <TR>
                        <TH><p style="color:red">Time</p></TH>
                    </TR>
                <TR>  
                    <TD>
                    <SELECT NAME="Time" ID="Time" style="width:220px">
                        <OPTION>
                        <OPTION>7:30-8:30
                        <OPTION>7:30-9:00
                        <OPTION>7:30-10:30
                    </SELECT>
                    </TD>

What happens is when the user click the submit button, it automatically call save.php

<?php
$time = $_POST['Time'];

//create connection_aborted
$conn = mysqli_connect("localhost", "root", "", "scheduling");
//check connection
if($conn-> connect_error) {
    die ("connection failed; ". $conn-> connect_error);
}
$sql = "INSERT INTO sched (Time)VALUES ('$time')";

$conn->close();
?>

This technique works on textbox, I don't know why can't get data from drop down list. Am I missing something? Please help to fix.

1
  • set the option value Commented Mar 1, 2019 at 2:22

3 Answers 3

1

You need set the option value like this:

<select id="Time" required>
  <option value="">Please Select</option>
  <option value="7:30-8:30">7:30-8:30</option>
  <option value="7:30-9:00">7:30-9:00</option>
  <option value="7:30-10:30">7:30-10:30</option>
</select> 

And if you have option with blank value, good to check in php first before insert like this

if (!empty($_POST['Time'])) $Time = $_POST['Time'];

Sign up to request clarification or add additional context in comments.

Comments

1

Your option tags need a value attribute to send to the server. Try this:

<SELECT NAME="Time" ID="Time" style="width:220px">
  <OPTION value=""></OPTION>
  <OPTION value="7:30-8:30">7:30-8:30</OPTION>
  <OPTION value="7:30-9:00">7:30-9:00</OPTION>
  <OPTION value="7:30-10:30">7:30-10:30</OPTION>
</SELECT>

Comments

0
<select id="Time" name="Time">
  <option disabled="disabled" selected="selected" value="">Please Select One</option>
  <option value="7:30-8:30">7:30-8:30</option>
  <option value="7:30-9:00">7:30-9:00</option>
  <option value="7:30-10:30">7:30-10:30</option>
</select>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.