How to set timestamp with this php script - php

I have this script. When I select the date then I get the data by selecting date, but I want to set this with timestamp
<link rel="stylesheet" type="text/css" href="tcal.css" />
<script type="text/javascript" src="tcal.js"></script>
<form action="index.php" method="get">
From : <input type="text" name="d1" class="tcal" value="" />
<input type="submit" value="Search">
</form>
<table id="resultTable" data-responsive="table" style="text-align: left; width: 400px;" border="1" cellspacing="0" cellpadding="4">
<thead>
<tr>
<th> Birtday </th>
<th> Name </th>
<th> Gender </th>
</tr>
</thead>
<tbody>
<?php
include('connect.php');
if (isset($_GET["d1"])) { $d1 = $_GET["d1"]; } else { $d1="0000-00-00"; };
$result = $db->prepare("SELECT * FROM birthday WHERE date = :a");
$result->bindParam(':a', $d1);
$result->execute();
for($i=0; $row = $result->fetch(); $i++){
?>
<tr class="record">
<td><?php echo $row['date']; ?></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['gender']; ?></td>
</tr>
<?php
}
?>
</tbody>
</table>
How I set timestamp with this script

Just use date() to echo out today's date as the value of your d1 input field:
<link rel="stylesheet" type="text/css" href="tcal.css" />
<script type="text/javascript" src="tcal.js"></script>
<form action="index.php" method="get">
From : <input type="text" name="d1" class="tcal" value="<?php echo date("m/d/Y"); ?>" />
<input type="submit" value="Search">
</form>

Ya the date - function will give all the information you need. If you havn't worked with it or just in case you are new to PHP, have a look at the documentation for finding the right date parameters.
For example:
date("d.m.Y") //outputs: 13.03.2014
date("n.d.Y") //outputs: 3.13.2014
date("m.d.y") //outputs: 03.13.14
The whole documentation can be found here: http://php.net/manual/en/function.date.php
EDIT::
So if I got you right you are looking for something simular like this:
<select class="Calendar" id="cdate_Month_ID" >
<option value="1" <?=(date('n')==1?'selected':'')?>>Jan</option>
<option value="2" <?=(date('n')==2?'selected':'')?>>Feb</option>
<option value="3" <?=(date('n')==3?'selected':'')?>>Mar</option>
<option value="4" <?=(date('n')==4?'selected':'')?>>Apr</option>
<option value="5" <?=(date('n')==5?'selected':'')?>>May</option>
<option value="6" <?=(date('n')==6?'selected':'')?>>Jun</option>
<option value="7" <?=(date('n')==7?'selected':'')?>>Jul</option>
<option value="8" <?=(date('n')==8?'selected':'')?>>Aug</option>
<option value="9" <?=(date('n')==9?'selected':'')?>>Sep</option>
<option value="10" <?=(date('n')==10?'selected':'')?>>Oct</option>
<option value="11" <?=(date('n')==11?'selected':'')?>>Nov</option>
<option value="12" <?=(date('n')==12?'selected':'')?>>Dec</option>
</select>
<select class="Calendar" id="cdate_Day_ID" >
<option <?=(date('d')==1?'selected':'')?>>1</option>
<option <?=(date('d')==2?'selected':'')?>>2</option>
<option <?=(date('d')==3?'selected':'')?>>3</option>
<option <?=(date('d')==4?'selected':'')?>>4</option>
<option <?=(date('d')==5?'selected':'')?>>5</option>
<option <?=(date('d')==6?'selected':'')?>>6</option>
<option <?=(date('d')==7?'selected':'')?>>7</option>
<option <?=(date('d')==8?'selected':'')?>>8</option>
<option <?=(date('d')==9?'selected':'')?>>9</option>
<option <?=(date('d')==10?'selected':'')?>>10</option>
<option <?=(date('d')==11?'selected':'')?>>11</option>
<option <?=(date('d')==12?'selected':'')?>>12</option>
<option <?=(date('d')==13?'selected':'')?>">13</option>
<option <?=(date('d')==14?'selected':'')?>>14</option>
<option <?=(date('d')==15?'selected':'')?>>15</option>
<option <?=(date('d')==16?'selected':'')?>>16</option>
<option <?=(date('d')==17?'selected':'')?>>17</option>
<option <?=(date('d')==18?'selected':'')?>>18</option>
<option <?=(date('d')==19?'selected':'')?>>19</option>
<option <?=(date('d')==20?'selected':'')?>>20</option>
<option <?=(date('d')==21?'selected':'')?>>21</option>
<option <?=(date('d')==22?'selected':'')?>>22</option>
<option <?=(date('d')==23?'selected':'')?>>23</option>
<option <?=(date('d')==24?'selected':'')?>>24</option>
<option <?=(date('d')==25?'selected':'')?>>25</option>
<option <?=(date('d')==26?'selected':'')?>>26</option>
<option <?=(date('d')==27?'selected':'')?>>27</option>
<option <?=(date('d')==28?'selected':'')?>>28</option>
<option <?=(date('d')==29?'selected':'')?>>29</option>
<option <?=(date('d')==30?'selected':'')?>>30</option>
<option <?=(date('d')==31?'selected':'')?>>31</option>
</select>
<input class="Calendar" type="text" size="4" maxlength="4" title="Year" value="<?=date('Y'?>">

Related

How to Block date & time if others user already chose that date & time

Right now i am developing a booking vehicle system using html,php,sql. I dont know how to describe my question but let me give a situation example.
user 1: want to book vehicle on 11 may 2017 # 0930 and the admin already approved this user form.
user 2: want to book vehicle at the same date & time as user 1 and here is the problem. How to block others user from proceed the booking if that date & time already have a user?
Hope you guys can help me, thank you!
this is my coding for date & time. it is in form for user to book and i want to make it once they click submit if that date & time already booked will pop up msg like 'already booked'.
<link rel="stylesheet" type="text/css" href="tcal.css" />
<script type="text/javascript" src="tcal.js"></script>
<script>
function myFunction() {
alert("Permohonan anda akan diproses. Sila jangan tutup paparan sehingga selesai.");
}
</script>
<form action="processform.php" method="post" enctype="multipart/form-data">
<table width="100%" align="center" cellpadding="2" cellspacing="4" bgcolor="#FFFFFF">
<br>
<br>
<tr bgcolor="#e2e8ef">
<td colspan="3" class="font12bold"> BUTIRAN PERJALANAN</td>
</tr>
<tr class="font12">
<td> Date to Depart <b class="icon_required" style="color:#FF0000">*</b></td>
<td align="center">:</td>
<td>
<input type="text" name="departDate" class="tcal" value="" />
<font class="font12gray">[dd-mm-yyyy]</font></td>
</tr>
<tr class="font12">
<td> Time to Depart <b class="icon_required" style="color:#FF0000">*</b></td>
<td align="center">:</td>
<td>
<select name="timeDepart">
<option value="-">-Sila Pilih-</option>
<option value="01:00" >1:00</option>
<option value="01:30" >1:30</option>
<option value="02:00" >2:00</option>
<option value="02:30" >2:30</option>
<option value="03:00" >3:00</option>
<option value="03:30" >3:30</option>
<option value="04:00" >4:00</option>
<option value="04:30" >4:30</option>
<option value="05:00" >5:00</option>
<option value="05:30" >5:30</option>
<option value="06:00" >6:00</option>
<option value="06:30" >6:30</option>
<option value="07:00" >7:00</option>
<option value="07:30" >7:30</option>
<option value="08:00" >8:00</option>
<option value="08:30" >8:30</option>
<option value="09:00" >9:00</option>
<option value="09:30" >9:30</option>
<option value="10:00" >10:00</option>
<option value="10:30" >10:30</option>
<option value="11:00" >11:00</option>
<option value="11:30" >11:30</option>
<option value="12:00" >12:00</option>
<option value="12:30" >12:30</option>
</select>
<select name="waktuDepart">
<option value="" > - </option>
<option value="Pagi" > Pagi</option>
<option value="Tengahari" >Tengahari</option>
<option value="Petang" >Petang</option>
<option value="Malam" >Malam</option>
</select>
</td>
</tr>
<tr class="font12">
<td> Date to Return <b class="icon_required" style="color:#FF0000">*</b></td>
<td align="center">:</td>
<td><input type="text" name="returnDate" class="tcal" value="" />
<font class="font12gray">[dd-mm-yyyy]</font></td>
</tr>
<tr class="font12">
<td> Time to Return <b class="icon_required" style="color:#FF0000">*</b></td>
<td align="center">:</td>
<td><select name="returnTime">
<option value="-">-Sila Pilih-</option>
<option value="01:00" >1:00</option>
<option value="01:30" >1:30</option>
<option value="02:00" >2:00</option>
<option value="02:30" >2:30</option>
<option value="03:00" >3:00</option>
<option value="03:30" >3:30</option>
<option value="04:00" >4:00</option>
<option value="04:30" >4:30</option>
<option value="05:00" >5:00</option>
<option value="05:30" >5:30</option>
<option value="06:00" >6:00</option>
<option value="06:30" >6:30</option>
<option value="07:00" >7:00</option>
<option value="07:30" >7:30</option>
<option value="08:00" >8:00</option>
<option value="08:30" >8:30</option>
<option value="09:00" >9:00</option>
<option value="09:30" >9:30</option>
<option value="10:00" >10:00</option>
<option value="10:30" >10:30</option>
<option value="11:00" >11:00</option>
<option value="11:30" >11:30</option>
<option value="12:00" >12:00</option>
<option value="12:30" >12:30</option>
</select>
<select name="waktuReturn">
<option value="" >- </option>
<option value="Pagi" >Pagi</option>
<option value="Tengahari" >Tengahari</option>
<option value="Petang" >Petang</option>
<option value="Malam" >Malam</option>
</select>
</td>
</tr>
</table>
<center><input type="submit" name="submit" value="Hantar" style="cursor:pointer" onclick="myFunction()"> [ kembali ]<br></center>
</td></tr></table>
</form>

PHP Form Multiple Lines into MySQL

i've searched and searched and maybe i found actually the right post but nothing worked for me so sorry for any duplication but maybe someone can help me out.
I have a php that gets me a form with multiple rows (based on an form input before).
Here's the php that creates the input table:
<html>
<head></head>
<body>
New report with EEM Number:<input type="text" name="eemnumber" />
<tr>
<td>Expense Date</td>
<td>Category</td>
<td>Vendor</td>
<td>Receipt Amount</td>
<td>Currency</td>
<td>Payment Amount</td>
<td>Currency</td>
<td>Payment Type</td>
<td>Country</td>
</tr>
<?php
$rows = $_POST['rows'];
$n = 0;
while($n < $rows)
{
$n++;
?>
<tr>
<td><input type="date" name="expensedate"/><br /></td>
<td><select name="category">
<option value="AirFare">AirFare</option> />
<option value="AutoRental">Auto Rental - Employee</option> />
<option value="DailyAllowance">Daily Allowance Standard</option> />
<option value="Gasoline">Gasoline - Auto Rental</option> />
<option value="Lodging">Lodging (Hotel) - Room / Tax</option> />
<option value="Meals">Meals / Entertain - HP only, Travel</option> />
<option value="Misc">Miscellaneous</option> />
<option value="Taxi">Taxi / Subway / Bus / Train</option> />
<br/>
</td>
<td><input type="text" name="vendor"/><br /></td>
<td><input type="text" name="receiptamount"/>
</td>
<td><select name="currrec">
<option value="EUR">EUR</option> />
<option value="SEK">SEK</option> />
<option value="USD">USD</option> />
</td>
<td><input type="text" name="paymentamount"/>
</td>
<td><select name="currpay">
<option value="EUR">EUR</option> />
<option value="SEK">SEK</option> />
<option value="USD">USD</option> />
</td>
<td><select name="paytype">
<option value="cash">Cash</option> />
<option value="cc">Credit Card</option> />
<br/>
</td>
<td><select name="country">
<option value="DE">Germany</option> />
<option value="SE">Sweden</option> />
<option value="US">USA</option> />
<br/>
</td>
</tr>
<?PHP
}
?>
</table>
</div>
<p>
<input type="submit"/>
</form>
<!-- End of FORM -->
Back
</body>
</html>
So once all data was entered I click on Submit and would of course like to get every line into my DB. Here's the script i tried do use but only gets me the last...
<?php
$con=mysqli_connect("localhost","user","pass","db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$eemnumber=$_POST['expensedate'];
$expensedate=$_POST['expensedate'];
$category=$_POST['category'];
$vendor=$_POST['vendor'];
$receiptamount=$_POST['receiptamount'];
$currrec=$_POST['currrec'];
$paymentamount=$_POST['paymentamount'];
$currpay=$_POST['currpay'];
$paytype=$_POST['paytype'];
$eemnumber=$_POST['eemnumber'];
$country=$_POST['country'];
$sql="INSERT INTO tbl_eem_data
(ExpenseDate, Category, Vendor, ReceiptAmount, CurrRec, PaymentAmount, CurrPay, PayType, EEMNumber, Country)
VALUES
$expensedate,
$category,
$vendor,
$receiptamount,
$currrec,
$paymentamount,
$currpay,
$paytype,
$eemnumber,
$country)";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
mysqli_close($con);
header("location:index.php");
?>
Anyone any clue?
Thanks!!!
You need to change form Structure and form Fields
<?php
$rows = $_POST['rows'];
$n = 0;
while($n < $rows)
{
$n++;
?>
<tr>
<td><input type="date" name="expensedate[<?echo $n?>]"/><br /></td>
<td><select name="category">
<option value="AirFare">AirFare</option> />
<option value="AutoRental">Auto Rental - Employee</option> />
<option value="DailyAllowance">Daily Allowance Standard</option> />
<option value="Gasoline">Gasoline - Auto Rental</option> />
<option value="Lodging">Lodging (Hotel) - Room / Tax</option> />
<option value="Meals">Meals / Entertain - HP only, Travel</option> />
<option value="Misc">Miscellaneous</option> />
<option value="Taxi">Taxi / Subway / Bus / Train</option> />
<br/>
</td>
<td><input type="text" name="vendor[<?echo $n?>]"/><br /></td>
<td><input type="text" name="receiptamount[<?echo $n?>]"/>
</td>
<td><select name="currrec">
<option value="EUR">EUR</option> />
<option value="SEK">SEK</option> />
<option value="USD">USD</option> />
</td>
<td><input type="text" name="paymentamount[<?echo $n?>]"/>
</td>
<td><select name="currpay[<?echo $n?>]">
<option value="EUR">EUR</option> />
<option value="SEK">SEK</option> />
<option value="USD">USD</option> />
</td>
<td><select name="paytype[<?echo $n?>]">
<option value="cash">Cash</option> />
<option value="cc">Credit Card</option> />
<br/>
</td>
<td><select name="country[<?echo $n?>]">
<option value="DE">Germany</option> />
<option value="SE">Sweden</option> />
<option value="US">USA</option> />
<br/>
</td>
</tr>
<?PHP
}
?>
<input type="hidden" name="rows" value="<?echo $n?>" />
Then apply similar loop to fetch those values.
You also need to have hidden variable which stores total number of rows you have.
Thanks
You seem to be missing an open parenthesis ( in your SQL right after VALUES.
Fix it and hopefully it will work: VALUES ( . . . )
Basically, run this test:
HTML:
<input type="text" name="key" value="1" />
<input type="text" name="key" value="2" />
PHP:
<?
print_r($_POST);
?>
And then run this:
HTML:
<input type="text" name="key[]" value="1" />
<input type="text" name="key[]" value="2" />
PHP:
<?
print_r($_POST);
?>
See if you can make any conclusions with this, and let me know what you think.
You are generating form fields based on the number of $rows received from the Request.
<form ... <!- this line was missing in your code -->
$rows = $_POST['rows'];
while($n < $rows)
...
</form>
And after submit, you are not reading parameters into arrays.
$eemnumber=$_POST['expensedate']; /* this is wrong again */
$expensedate=$_POST['expensedate'];
$category=$_POST['category'];
$vendor=$_POST['vendor'];
Which lead the last value from the submitted array values assigned to the variable in concern.
And hence you see that only last row read and pushed into DB.
Change your code accordingly and it should be working.
Refer to:
PHP: Reading POST data with arrays

How to get values from a multiple checkbox and insert into database?

I am working on a certain form that accepts multiple values using checkbox and I find it hard to get all the values of the checked boxes and store them into the database.
Everytime my insertion query is being executed.. the only value that is stored in the database is the last checkbox the user selects thus ignoring the others..
here's my code:
----form-----------------------------------------------------------------'
<form name="addRes" method="post" action="addReservation_code.php">
<table>
<tr><td>Activity Date:</td>
<td><select name="month">
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value"December">December</option>
</select>
<select name="day">
<?php for($ctr=1;$ctr<=31;$ctr++){ ?>
<option value="<?php print($ctr); ?>"><?php print($ctr); ?></option>
<?php } ?>
</select> -
<select name="day2">
<?php for($ctr=1;$ctr<=31;$ctr++){ ?>
<option value="<?php print($ctr); ?>"><?php print($ctr); ?></option>
<?php } ?>
</select>
<input type="text" name="year"/></td>
</tr>
<tr><td>Activity Name:</td><td><input type="text" name="act_name" /></td></tr>
<tr><td>Activity Time:</td><td><input type="text" name="act_time" /></td></tr>
<tr><td>Room:</td>
<td>
<select name="room">
<?php
include 'RRSdbconnect.php';
$query = "SELECT room_name from room";
$result=mysql_query($query) or die('Invalid query'.mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_BOTH))
{
echo "<option>$row[room_name]";
}
?>
</option>
</select>
</td>
</tr>
<tr>
<td>Resources Needed:</td>
<td><input type="checkbox" name="resources" value="cpu" />CPU<br />
<input type="checkbox" name="resources" value="lcd" />LCD<br />
<input type="checkbox" name="resources" value="sounds" />Sounds<br />
<input type="checkbox" name="resources" value="sounds" />Others, Pls. specify<input type="text" name="others" /></td>
</tr>
<tr><td>No. of Person</td><td><input type="text" name="noOfPerson"/></td></tr>
<tr><td>Reserved by:</td><td><input type="text" name="reservedby" /></td></tr>
<tr><td></td></tr>
<tr><td><input type="submit" name="submit" value="Submit"/><input type="reset" name="clear" value="Clear"/></td></tr>
</table>
</form>
------------action code----------------------------------------------------
<?php
include 'RRSdbconnect.php';
session_start();
$date = $_POST['month'] . ' ' .$_POST['day']. '-' .$_POST['day2']. ', ' . $_POST['year'] ;
$name=$_POST['act_name'];
$time=$_POST['act_time'];
$room=$_POST['room'];
$resources=$_POST['resources'];
$noOfPerson=$_POST['noOfPerson'];
$reservedby=$_POST['reservedby'];
//insertions for add reservations
$query="insert into reservation (activity_date, activity_name, activity_time, room, resources_needed, no_person, reserved_by) values('$date','$name','$time','$room','$resources','$noOfPerson','$reservedby')";
$result=mysql_query($query,$link) or die("Error!".mysql_error());
?>
PS.
I am using checkbox on the column resources needed..
any help will be appreciate..tnx
If you change the name attribute of the checkbox to name="resources[]" you should get an array in the $_POST['resources']
Once you have the array in $_POST['resources']you can store/retrieve it in the database how you like. For example either as a string using implode() / explode() or serialize() / unserialize().

How to get a form select to come back with the option value, to be then used with a PHP if statment?

<?php
$home = "/index.php";
$aboutus = "/aboutus.php";
$contact = "/contact.php";
$contact_reply = "/contact_reply.php";
$current = $_SERVER['REQUEST_URI'];
if ($contact==$current)
{
print " ";
}
else
{
if (isset($_POST["op"])){
$message = "";
foreach ($HTTP_POST_VARS['myselect'] as $value)
{
$message .= $value;
if($message=="2")
{
echo "number 2 is selected";
}
else
{
echo "number gay";
}
};
}
else {
print '
<form method="post" action ><input name="op" TYPE="hidden" VALUE="send">
<select name="myselect[]" size="6" multiple="multiple">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
<select name="myselect[]"/>
<option value="#">-Select-</option>
<option title="car" value="car">Car</option>
<option value="USA">USA</option>
</select>
<input type="image" src="images/go.gif" alt="Go" name="submit" id="submit" value="Submit"/>
</form>
';}
if($type=="car")
{
print '
<form method="post" action="details.php" enctype="multipart/form-data">
<table class="search_nav">
<tr>
<td>
<select name="manufacture" id="manufacture">
<option value=" " selected="selected">Car Manufactures</option>
<option value="audi">Audi</option>
<option value="fiat">Fiat</option>
<option value="ford">Ford</option>
<option value="land_rover">Land Rover</option>
<option value="mini">Mini</option>
<option value="toyota">Toyota</option>
<option value="vauxhaul">Vauxhaul</option>
<option value="volkswagen">Volkswagen</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="image" src="images/go.gif" alt="Go" name="submit" id="submit" value="Submit"/>
</td>
</tr>
</table>
</form>
<form method="post" action="details_bikes.php" enctype="multipart/form-data">
<table class="search_nav">
<tr>
<td>
<select name="manufacture" id="manufacture">
<option value=" " selected="selected">Car Manufactures</option>
<option value="ducati">Ducati</option>
<option value="fiat">Fiat</option>
<option value="ford">Ford</option>
<option value="land_rover">Land Rover</option>
<option value="mini">Mini</option>
<option value="toyota">Toyota</option>
<option value="vauxhaul">Vauxhaul</option>
<option value="volkswagen">Volkswagen</option>
</select>
</td>
</tr>
<tr>
<td colspan="2">
<input type="image" src="images/go.gif" alt="Go" name="submit" id="submit" value="Submit"/>
</td>
</tr>
</table>
';
}
else
{
}
When the form is submitted via POST, the select field will have the selected value sent to it via the $_POST array.
$value = $_POST['myselect']
echo $value;
what so would something like this work? $value = ''; $_POST['myselect'] = $value; print $value; – Robert 9 mins ago
That doesn't work, just tried it and nothing is being displayed :s – Robert 0 secs ago edit

How to get multiple selected values of select box in php?

I have a html form which has a select list box from which you can select multiple values because its multiple property is set to multiple. Consider form method is 'GET'. The html code for the form is as follows:
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="get" action="display.php">
<table width="300" border="1">
<tr>
<td><label>Multiple Selection </label> </td>
<td><select name="select2" size="3" multiple="multiple" tabindex="1">
<option value="11">eleven</option>
<option value="12">twelve</option>
<option value="13">thirette</option>
<option value="14">fourteen</option>
<option value="15">fifteen</option>
<option value="16">sixteen</option>
<option value="17">seventeen</option>
<option value="18">eighteen</option>
<option value="19">nineteen</option>
<option value="20">twenty</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" tabindex="2" /></td>
</tr>
</table>
</form>
</body>
</html>
I want to display the selected values in select list box on display.php page. So how are the selected values accessed on display.php page using $_GET[] array.
If you want PHP to treat $_GET['select2'] as an array of options just add square brackets to the name of the select element like this: <select name="select2[]" multiple …
Then you can acces the array in your PHP script
<?php
header("Content-Type: text/plain");
foreach ($_GET['select2'] as $selectedOption)
echo $selectedOption."\n";
$_GET may be substituted by $_POST depending on the <form method="…" value.
Change:
<select name="select2" ...
To:
<select name="select2[]" ...
You can use this code to retrieve values from multiple select combo box
HTML:
<form action="c3.php" method="post">
<select name="ary[]" multiple="multiple">
<option value="Option 1" >Option 1</option>
<option value="Option 2">Option 2</option>
<option value="Option 3">Option 3</option>
<option value="Option 4">Option 4</option>
<option value="Option 5">Option 5</option>
</select>
<input type="submit">
</form>
PHP:
<?php
$values = $_POST['ary'];
foreach ($values as $a){
echo $a;
}
?>
Use the following program for select the multiple values from select box.
multi.php
<?php
print <<<_HTML_
<html>
<body>
<form method="post" action="value.php">
<select name="flower[ ]" multiple>
<option value="flower">FLOWER</option>
<option value="rose">ROSE</option>
<option value="lilly">LILLY</option>
<option value="jasmine">JASMINE</option>
<option value="lotus">LOTUS</option>
<option value="tulips">TULIPS</option>
</select>
<input type="submit" name="submit" value=Submit>
</form>
</body>
</html>
_HTML_
?>
value.php
<?php
foreach ($_POST['flower'] as $names)
{
print "You are selected $names<br/>";
}
?>
<html>
<head>
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="get" action="display.php">
<table width="300" border="1">
<tr>
<td><label>Multiple Selection </label> </td>
<td><select name="select2[]" size="3" multiple="multiple" tabindex="1">
<option value="11">eleven</option>
<option value="12">twelve</option>
<option value="13">thirette</option>
<option value="14">fourteen</option>
<option value="15">fifteen</option>
<option value="16">sixteen</option>
<option value="17">seventeen</option>
<option value="18">eighteen</option>
<option value="19">nineteen</option>
<option value="20">twenty</option>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="Submit" tabindex="2" /></td>
</tr>
</table>
</form>
</body>
</html>
You can iterate it directly like this
foreach ($_GET['select2'] as $value)
echo $value."\n";
or you can do it like this
$selectvalue=$_GET['select2'];
foreach ($selectvalue as $value)
echo $value."\n";
This will display the selected values:
<?php
if ($_POST) {
foreach($_POST['select2'] as $selected) {
echo $selected."<br>";
}
}
?>
// CHANGE name="select2" TO name="select2[]" THEN
<?php
$mySelection = $_GET['select2'];
$nSelection = count($MySelection);
for($i=0; $i < $nSelection; $i++)
{
$numberVal = $MySelection[$i];
if ($numberVal == "11"){
echo("Eleven");
}
else if ($numberVal == "12"){
echo("Twelve");
}
...
...
}
?>
You could do like this too. It worked out for me.
<form action="ResultsDulith.php" id="intermediate" name="inputMachine[]" multiple="multiple" method="post">
<select id="selectDuration" name="selectDuration[]" multiple="multiple">
<option value="1 WEEK" >Last 1 Week</option>
<option value="2 WEEK" >Last 2 Week </option>
<option value="3 WEEK" >Last 3 Week</option>
<option value="4 WEEK" >Last 4 Week</option>
<option value="5 WEEK" >Last 5 Week</option>
<option value="6 WEEK" >Last 6 Week</option>
</select>
<input type="submit"/>
</form>
Then take the multiple selection from following PHP code below. It print the selected multiple values accordingly.
$shift=$_POST['selectDuration'];
print_r($shift);
I fix my problem with javascript + HTML. First i check selected options and save its in a hidden field of my form:
for(i=0; i < form.select.options.length; i++)
if (form.select.options[i].selected)
form.hidden.value += form.select.options[i].value;
Next, i get by post that field and get all the string ;-)
I hope it'll be work for somebody more. Thanks to all.
foreach ($_POST["select2"] as $selectedOption)
{
echo $selectedOption."\n";
}
form submit with enctype="multipart/form-data"

Categories