I want to echo selected value from dropdown. But it always give me the output: Default
Kindly check what I am doing:
<div>
<select id="orderStatus" name="orderStatus">
<option value="0"></option>
<option value="Available">Available</option>
<option value="Arranging Product">Arranging Product</option>
<option value="Awaiting Fulfillment">Awaiting Fulfillment</option>
<option value="Awaiting Payment">Awaiting Payment</option>
<option value="Awaiting Pickup">Awaiting Pickup</option>
<option value="Awaiting Shipment">Awaiting Shipment</option>
</select>
// I think here is the problem when I click button it forgets selected index value
Update
</div>
Php Code:
<?php
$draft = isset($_GET['orderStatus'])? $_GET['orderStatus'] : 'DEFAULT';
echo $draft;
?>
When I click on update button then in the output I always get DEFAULT. I think when I click on the update button it forgets the selected index value.
Kindly suggest what I am doing wrong.
Add to tag onmousedown event:
<div>
<select id="orderStatus" name="orderStatus">
<option value="0"></option>
<option value="Available">Available</option>
<option value="Arranging Product">Arranging Product</option>
<option value="Awaiting Fulfillment">Awaiting Fulfillment</option>
<option value="Awaiting Payment">Awaiting Payment</option>
<option value="Awaiting Pickup">Awaiting Pickup</option>
<option value="Awaiting Shipment">Awaiting Shipment</option>
</select>
// I think here is the problem when I click button it forgets selected index value
Update
</div>
This send your parametr as GET request
<div>
<form method="GET" action="order.php">
<select id="orderStatus" name="orderStatus">
<option value="0"></option>
<option value="Available">Available</option>
<option value="Arranging Product">Arranging Product</option>
<option value="Awaiting Fulfillment">Awaiting Fulfillment</option>
<option value="Awaiting Payment">Awaiting Payment</option>
<option value="Awaiting Pickup">Awaiting Pickup</option>
<option value="Awaiting Shipment">Awaiting Shipment</option>
</select>
<button type="submit" class="btn btn-large">Update</button>
</form>
</div>
Try This , Its working :
<?php
if(isset($_POST['submit'])){
$value = $_POST['orderStatus'];
echo $value;
}
?>
<form action="" method="post">
<select id="orderStatus" name="orderStatus">
<option value="0"></option>
<option value="Available">Available</option>
<option value="Arranging Product">Arranging Product</option>
<option value="Awaiting Fulfillment">Awaiting Fulfillment</option>
<option value="Awaiting Payment">Awaiting Payment</option>
<option value="Awaiting Pickup">Awaiting Pickup</option>
<option value="Awaiting Shipment">Awaiting Shipment</option>
</select>
<input type="submit" name="submit" value="Update" />
</form>
Related
I am.working on a user input availability database. I order to standardize the information, I want to use more than 1 mulitiple select inputs.
<form method="post" action=''example.php">
Gamerid:<input ="text" name ="gamerid"/></br>
Monday:<select name="monday[]" multiple="multiple">
<option>Select your availability</option>
<option value="4">4pm</option>
<option value="5">5pm</option>
<option value="6">6pm</option>
<option value="7">7pm</option>
<option value="8">8pm</option>
<option value="9">9pm</option>
<option value="10">10pm</option>
<option value="11">11pm</option>
<option value="12">12pm</option>
<option value="1a">1am</option>
</select> </br>
Tuesday:<select name="tuesday[]"multiple="multiple">
<option>Select your availability</option>
<option value="4">4pm</option>
<option value="5">5pm</option>
<option value="6">6pm</option>
<option value="7">7pm</option>
<option value="8">8pm</option>
<option value="9">9pm</option>
<option value="10">10pm</option>
<option value="11">11pm</option>
<option value="12">12pm</option>
<option value="1a">1am</option>
</select> </br>
Wednesday:<select name="wednesday[]" multiple="multiple">
<option>Select your availability</option>
<option value="4">4pm</option>
<option value="5">5pm</option>
<option value="6">6pm</option>
<option value="7">7pm</option>
<option value="8">8pm</option>
<option value="9">9pm</option>
<option value="10">10pm</option>
<option value="11">11pm</option>
<option value="12">12pm</option>
<option value="1a">1am</option>
</select> </br>
etc for every day of the week.. so far, I believe my code is correct but POST seems to not appreciate it. Is it even possible..?
The end goal it to serialise the $_POST arrays, into strings, then store them in sql db.
Any help here would be appreciated.
In action page you will get array then by using implode you can convert to string then you can insert in to database.
try for this code.
<form method="post">
Tuesday:<select name="tuesday[]"multiple="multiple">
<option>Select your availability</option>
<option value="4">4pm</option>
<option value="5">5pm</option>
<option value="6">6pm</option>
<option value="7">7pm</option>
<option value="8">8pm</option>
<option value="9">9pm</option>
<option value="10">10pm</option>
<option value="11">11pm</option>
<option value="12">12pm</option>
<option value="1a">1am</option>
</select>
<input type="submit" name="submit">
</form>
<?php
if(isset($_POST['submit'])){
$var=$_POST['tuesday'];
echo implode(",",$var);
}
?>
I have a multiple=multiple drop down list and I want to check if a user has selected any option or not using PHP code. If not, then I want to display an error message. How can I do that?
<select name="ddlskill" multiple="multiple">
<option value="Cake PHP">Cake PHP</option>
<option value="Database">Database</option>
<option value="hello">hello</option>
<option value="Java">Java</option>
<option value="Jquery">Jquery</option>
<option value="JSON">JSON</option>
<option value="JSP">JSP</option>
<option value="Mysql">Mysql</option>
<option value="PHP">PHP</option>
<option value="xyz">xyz</option>
<option value="XYZ2">XYZ2</option>
</select>
You should declare your html like this :
<select name="ddlskill[]" multiple="multiple">
<option value="Cake PHP">Cake PHP</option>
<option value="Database">Database</option>
<option value="hello">hello</option>
<option value="Java">Java</option>
<option value="Jquery">Jquery</option>
<option value="JSON">JSON</option>
<option value="JSP">JSP</option>
<option value="Mysql">Mysql</option>
<option value="PHP">PHP</option>
<option value="xyz">xyz</option>
<option value="XYZ2">XYZ2</option>
</select>
And then in PHP, you'll get an array of values :
if( !empty($_POST['ddlskill']) ){
print_r($_POST['ddlskill']);
// [PHP, JSP, Java, ...]
}
Maybe helpful,
<?php
if( isset($_POST) && !empty($_POST['ddlskill'])){
echo "<pre>";print_r($_POST['ddlskill']);
// [PHP, JSP, Java, ...]
}
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post">
<select name="ddlskill[]" multiple="multiple">
<option value="Cake PHP">Cake PHP</option>
<option value="Database">Database</option>
<option value="hello">hello</option>
<option value="Java">Java</option>
<option value="Jquery">Jquery</option>
<option value="JSON">JSON</option>
<option value="JSP">JSP</option>
<option value="Mysql">Mysql</option>
<option value="PHP">PHP</option>
<option value="xyz">xyz</option>
<option value="XYZ2">XYZ2</option>
</select>
<button type="submit"> Submit </button>
</form>
<?php
if(!empty($_POST['submit'])){
if(is_array($_POST['ddlskill']))
{
foreach($_POST['ddlskill'] as $key=>$value)
{
print_r($value);
}
}
else
{
print_r($_POST['ddlskill']);
}
}
?>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post">
<select name="ddlskill[]" multiple="multiple">
<option value="Cake PHP">Cake PHP</option>
<option value="Database">Database</option>
<option value="hello">hello</option>
<option value="Java">Java</option>
<option value="Jquery">Jquery</option>
<option value="JSON">JSON</option>
<option value="JSP">JSP</option>
<option value="Mysql">Mysql</option>
<option value="PHP">PHP</option>
<option value="xyz">xyz</option>
<option value="XYZ2">XYZ2</option>
</select>
<button type="submit" name="submit"> Submit </button>
</form>
I'm having trouble getting my form's post data to come through. As this code stands, the file uploads, but I don't have any post data for the other form fields. I noticed that if I get rid of multipart/form-data enctype, it will not upload (obviously) but I DO get the post data to come through for the other fields. Any ideas on why this is?
The page where this code occurs is index.php?page=page1&upload=1
<form enctype="multipart/form-data" action="?page=page1&upload=2" method="post">
Select Location: <select name="location">
<option>Select Location</option>
<option value="N">North</option>
<option value="S">South</option>
<option value="E">East</option>
<option value="W">West</option>
</select><br />
Upload File: <input name="ufile" type="file" id="ufile" size="50" /><br />
<b><u>Sunday</u></b> Date: <select name="month">
<option> - Month - </option>
<option value="01">January</option>
<option value="02">Febuary</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="day">
<option> - Day - </option>
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
<option value="05">5</option>
<option value="06">6</option>
<option value="07">7</option>
<option value="08">8</option>
<option value="09">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<select name="year">
<?php
$optionyear = date("Y",time());
$currentyear = $optionyear;
while($optionyear != 1990) {
echo "<option value=\"".$optionyear."\"";
if($optionyear == $currentyear) {
echo " selected";
}
echo ">".$optionyear."</option>";
$optionyear--;
}
?>
</select><br />
<input type="submit" name="Submit" value="Upload" /><br />
</form>
Thanks!
U can get your upload data with $_FILES[] and other data with $_POST[]
Try
echo "<pre>";
print_r($_POST);
print_r($_FILES['ufile']);
echo "</pre>";
By the way where is close tag for <form> element?
This is what I got so far, it's just the dropdown list. It's a form for making a reservation for appointment. I want to print out these selected values (= selected options of dropdown)
But I have no clue since I'm very new with PHP and HTML. Something with $_POST and $_GET ? Could I have some suggestions of solution? Much gratitude.
<html>
<head>
<title>title</title>
</head>
<body>
<select name="Ar" id="Ar">
<option value="1">2014</option>
<option value="2">2015</option>
<option value="3">2016</option>
<option value="4">2017</option>
<option value="5">2018</option>
<option value="6">2019</option>
</select>
<select name="Manad" id="Manad">
<option value="1">Januari</option>
<option value="2">Februari</option>
<option value="3">Mars</option>
<option value="4">April</option>
<option value="5">Maj</option>
<option value="6">Juni</option>
<option value="7">July</option>
<option value="8">Augusti</option>
<option value="9">September</option>
<option value="10">Oktober</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="Dag" id="Dag">
<option value="1">Mandag</option>
<option value="2">Tisdag</option>
<option value="3">Onsdag</option>
<option value="4">Torsdag</option>
<option value="5">Fredag</option>
</select>
<select name="Tid" id="Tid">
<option value="1">07:00</option>
<option value="2">08:00</option>
<option value="3">09:00</option>
<option value="4">10:00</option>
<option value="5">11:00</option>
<option value="6">12:00</option>
<option value="7">13:00</option>
<option value="8">14:00</option>
<option value="9">15:00</option>
<option value="10">16:00</option>
<option value="11">17:00</option>
<option value="12">18:00</option>
</select>
<input type="submit" name="submit" id="submit" value="Boka" />
</body>
</html>
You're missing the <form> tag. It should be wrapped around all your form-data (select, input) etc. Then you will fetch it using either $_GET or $_POST or even $_REQUIRE
Example (change site.php to whatever you please):
<html>
<head>
<title>title</title>
</head>
<body>
<form method="post" action="site.php">
<select name="Ar" id="Ar">
<option value="1">2014</option>
<option value="2">2015</option>
<option value="3">2016</option>
<option value="4">2017</option>
<option value="5">2018</option>
<option value="6">2019</option>
</select>
<select name="Manad" id="Manad">
<option value="1">Januari</option>
<option value="2">Februari</option>
<option value="3">Mars</option>
<option value="4">April</option>
<option value="5">Maj</option>
<option value="6">Juni</option>
<option value="7">July</option>
<option value="8">Augusti</option>
<option value="9">September</option>
<option value="10">Oktober</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select name="Dag" id="Dag">
<option value="1">Mandag</option>
<option value="2">Tisdag</option>
<option value="3">Onsdag</option>
<option value="4">Torsdag</option>
<option value="5">Fredag</option>
</select>
<select name="Tid" id="Tid">
<option value="1">07:00</option>
<option value="2">08:00</option>
<option value="3">09:00</option>
<option value="4">10:00</option>
<option value="5">11:00</option>
<option value="6">12:00</option>
<option value="7">13:00</option>
<option value="8">14:00</option>
<option value="9">15:00</option>
<option value="10">16:00</option>
<option value="11">17:00</option>
<option value="12">18:00</option>
</select>
<input type="submit" name="submit" id="submit" value="Boka" />
</form>
</body>
</html>
PHP example:
if(isset($_POST['Ar'])) { // Make sure it's sent
$year = $_POST['Ar'];
echo "År: " . htmlentities($year); // Output (htmlentities for safety when outputting)
$month = $_POST['Manad'];
echo "Månad: " . htmlentities($month);
}
I have the following date picker with 3 different select ids
<form id="testform" method="get" action="../Untitled-1.html">
<select id="date-sel-dd" name="date-sel-dd">
<option value="-1">Day</option>
<option value="1">1st</option>
<option value="2">2nd</option>
<option value="3">3rd</option>
<option value="4">4th</option>
<option value="5">5th</option>
<option value="6">6th</option>
<option value="7">7th</option>
<option value="8">8th</option>
<option value="9">9th</option>
<option value="10">10th</option>
<option value="11">11th</option>
<option value="12">12th</option>
<option value="13">13th</option>
<option value="14">14th</option>
<option value="15">15th</option>
<option value="16">16th</option>
<option value="17">17th</option>
<option value="18">18th</option>
<option value="19">19th</option>
<option value="20">20th</option>
<option value="21">21st</option>
<option value="22">22nd</option>
<option value="23">23rd</option>
<option value="24">24th</option>
<option value="25">25th</option>
<option value="26">26th</option>
<option value="27">27th</option>
<option value="28">28th</option>
<option value="29">29th</option>
<option value="30">30th</option>
<option value="31">31st</option>
</select>
<select id="date-sel-mm" name="date-sel-mm">
<option value="-1">Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<select id="date-sel" name="date-sel">
<option value="-1">Year</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
</select>
<input type="submit" name="submit" id="submit" value="Submit" />
I need to get the values from these 3 differnt select fields and post it with the form to a new named: 'arrival'.
When I submit to the page I want my url to look like:
mydomain.php?arrival=date-sel-dd/date-sel-mm/date-sel
You could use an array.
Rename all select with arrival[].
In your php page you can get that value as an array. Try:
print_r($_POST['arrival']);
If you want to join the date use:
$date = implode('/', $_POST['arrival']);
header('Location: mydomain.php?arrival=' . $date);