V
V
Vyacheslav2015-11-11 09:52:51
PHP
Vyacheslav, 2015-11-11 09:52:51

How to write in session selected value in select?

Forming a list

<select id="sel_">
    <?php
      $query_= "SELECT * FROM category_information";
      $sql_q=mysql_query($query_);
          
      while ($row = mysql_fetch_row($sql_q))
        {
          echo '<option name="op_cat_id" value="'.$row[0].'">'.$row[1].'</option>';
        }

        
    ?>
</select>

How, when selecting the "op_cat_id" element, write "value" to the session?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
OnYourLips, 2015-11-11
@OnYourLips

How, when selecting the "op_cat_id" element, write "value" to the session?

The choice occurs in the browser, and you can write to the session on the server.
Means it is necessary to transfer event from the browser to the server. For example, through AJAX.

V
Viktor, 2015-11-11
@master2016

Look for the selected element not by the option name, but by the name or identifier select
For example, by attaching a script to the select:
$('#sel_').change(function(){
var id = $(this).val();
// and then you push the value into the session with Ajax
});

V
Valery Zinchenko, 2015-11-16
@officialmuse

It is possible through cookies: <?
// send cookie
setcookie("cookie[select]", $row[0]);
// after page reload, output cookie
if (isset($_COOKIE['cookie'])) {
foreach ($_COOKIE['cookie'] as $name => $value) {
$name = htmlspecialchars($name);
$value = htmlspecialchars($value);
echo "$name : $value
\n";
}
}
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question