The last while value is always session . How can I make the selected value get into session?

  <input name='date_t' type="hidden" value='<? echo $item['goods_id']?>'> <?php $id = $item['goods_id']; ?> <select name="data" > <option>Выберите Дату</option> <? $res = mysql_query("select date_trip from dates_trip where goods_t_id='$id'"); while( $row = mysql_fetch_array($res)){ ?> <option value="<?=$row['date_trip']?>"> <?=$row['date_trip']?></option> <? $_SESSION['data'] = $row['date_trip']; } ?> </select> <? echo $_SESSION['data']; ?> 
  • An example show? - Invision
  • $_SESSION['data'][] probably worth doing - Alexey Shimansky

1 answer 1

The selected value must be saved after sending the form data to the server. In your example, the back-end save the last value of the iteration of the options array; this will not affect the choice of customer values.

Example of sending form data as a POST request

http://codepen.io/anon/pen/eZKbQb


In the context of your implementation

 <?php if (isset($_POST['data'])) $_SESSION['data'] = $_POST['data']; ?> <form action="" method="post"> <input name='date_t' type="hidden" value='<? echo $item['goods_id']?>'> <?php $id = $item['goods_id']; ?> <select name="data" > <option>Выберите Дату</option> <? $res = mysql_query("select date_trip from dates_trip where goods_t_id='$id'"); while( $row = mysql_fetch_array($res)){ ?> <option value="<?=$row['date_trip']?>"> <?=$row['date_trip']?></option> ?> </select> <button>Submit</button> </form> <? if (isset($_SESSION['data'])) echo $_SESSION['data']; ?>