im facing problem in retaining values after submitting or reloading the php forms...plz help

Recommended Answers

All 3 Replies

Store it in a session if you need to keep it for an indefinite amount of time. If you need the user to re-enter some information but keep this value the same, add


inside the <option> tag.

You could use something like:

<form method="post" action="page.php">
   <select name="people" id="people">
    <?php if($_POST['submitted'] == true){ ?>
        <option value="<?php echo $_POST['people']; ?>" selected="selected"><?php echo $_POST['people']; ?></option>
    <?php }else{ ?>
      <option value=""> -- select -- </option>
    <?php } ?>
       <option value="" disabled="disabled"> -------- </option>
       <option value="Person 1">Person 1</option>
       <option value="Person 2">Person 2</option>
   <input type="submit" id="submit" name="submit" value="Submit" />
   <input type="hidden" name="submitted" id="submitted" value="true" />
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.