mysql - Pulling multiple fields from database using forms and php -
i have database multiple rows various fields.
i have form contains drop down list. drop down list displays 1 of database fields (field_name) each row in database.
when user selects desired entry hits submit, value passed results.php page , can used via $_post.
all of works.
i way send rest of row's fields correspond row of selected field (not "field_name") database along selected drop down menu.
for instance, if have database rows fields named "name", "date", , "age", have database rows "name"s appear in drop down list , once submitted, pass particular name's "date" , "age" on results.php use on page.
<html> <head> <title>drop down test</title> </head> <body style="font-family: verdana; font-size: 11px;"> <?php //variables connecting database. $hostname = "abcd"; $username = "abcd"; $dbname = "abcd"; $password = "abcd"; $usertable = "abcd"; //connecting database $connection = mysql_connect($hostname, $username, $password) or die ("unable connect database!"); $db = mysql_select_db($dbname); $query = "select * abcd"; $result = mysql_query($query) or die(mysql_error()); ?> <h2>drop down test form</h2> <p>please fill out form below , click submit.</p> <form action="results.php" method="post"> <p>drop down test: <select name='event'> <!-- drop down --> <?php while($row = mysql_fetch_array($result)) { echo '<option>' . $row['field_name']. '</option>'; } ?> </select> <p><input type="submit" value="submit"><p> </form>
you should put value
on option this:
echo '<option value = "'.$row['field_name'].'" name = "">' . $row['field_name']. '</option>';
then can access $_post['event'];
update
getting values select, can use $_session
variables pass other php.file.
Comments
Post a Comment