<?php $query= "SELECT date, id FROM Puspa ORDER BY id ASC"; $result = $db_connect->query($query); ?> <form action="output.php" method="post"> <select name='p'> <?php while (list($date, $id) = $result->fetch_row()) { echo "<option value=\"$id\"> $id : $date</option>"; } ?> </select> <input type="submit" value="submit"/><br /> </form> I've dynamically listed my result in dropdown list as the code above. I would like to know the shortcut and secure way to submit the SELECTED value using POST method. How to do this?
just pull the data after submission as if($_POST['p']){ $item = $_POST['p']; } Then you can sanitize it after you grab the submitted data.
Are you sure about it? The HTML code for drop down list will look like this: <select name='p'> <option value='1'>Value 1</option> <option value='2'>Value 2</option> <option value='3'>Value 3</option> </select> how will it pull the value? I know how to pull the value. But I wanted to get for example, Value 2 in $_POST['p']....
lowridertj is correct. The post value "p" is populated with what is selected in the dropdown. Also, don't forget to use "==" in your while loop: while (list($date, $id) == $result->fetch_row()) HTML: