Gopipuli
Gopipuli

Reputation: 393

how to keep value in a listbox in PHP?

I got a listbox in my php page that generate from another listbox, the code is as follows

<?php $myArray1 = $_POST['countryRF'];?>
                    <select name='countryRF[]' id='countryRF' size='10' multiple style='width:180px' class='selfont'>
                    <?php
                    foreach($myArray1 as $value){ // Loop through each element
                          print "<option value=\"".$value."\">".$value."</option>";
                    }
                    ?>
                    </option></select>

While refreshing the form listbox get empty, how can I keep added values even after form reload ?

Is it possible to keep the mysql result table stable even after form reloading by session ? If so please give me a help ?

Upvotes: 0

Views: 527

Answers (2)

galchen
galchen

Reputation: 5290

i see you get the 'countryRF' from post.

you can store it in a cookie/session, of store it on the server.

use

if (isset($_POST['countryRF'])) {
    $_COOKIE['countryRF'] = $_POST['countryRF'];
}
$myArray = $_COOKIE['countryRF'];

same goes with session

Upvotes: 1

genesis
genesis

Reputation: 50976

save them into Sessions

Upvotes: 1

Related Questions