开发者

PHP MySQL Dropdown box

I have a dropdown box which is populated through MySQL:

echo "<form>";<br>
echo "Please Select Your Event<br />";
echo "<select>";
$results = mysql_query($query)
    or die(mysql_error());
    while ($row = mysql_fetch_array($results)) {
    echo "<option>";
    echo $row['eventname'];
    echo "</option>";
    }   
echo 开发者_开发问答"</select>";
echo "<input type='submit' value='Go'>";
echo "</form>";

How do i make it that if one clicks submit it will display a value from a MySQL db

Thanks for the help


Just change your query like SELECT result FROM somedb WHERE eventname = '".$eventname."'

Then you just do: (remember to check before while has user already requested info)

The value was: <?php print $row["result"]; ?>

Remember to check $_POST["eventname"] with htmlspecialchars before inserting it to query.


1) Give a name to your <select>, i.e. <select name='event'>.

2) Redirect your form to the display page (and set method POST): <form method='POST' action='display.php'>

3) just display the selected value: <?php echo $_POST['event']; ?>


If you want to use the same page, give a name to your submit button and then do this:

<?php
   if (isset($_POST['submit']))
      echo $_POST['event'];
?>

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜