Jump to content

[SOLVED] Passing data from a drop down menu


jeaker

Recommended Posts

I have a website that I am working on. When the user logs in they see a drop down box and they are supposed to go to this box and select their name. How would I get the selection that they made to pass to the next page.

 

This is my code for the page with the drop down box that I have so far. It pulls from my database, and it works fine.

<?php
  // Connect to the upload datbase on localhost.
  mysql_connect('localhost','user','password');
  mysql_select_db('upload');

  // Query the teacher table and load all of the records
  // into an array.
  $sql = 'SELECT * FROM teacher';
  $res = mysql_query($sql) or die(mysql_error());
  while ($rec = mysql_fetch_assoc($res)) $teacher[] = $rec;
?>
<title>Untitled Document</title>
</head>

<body>
<?php
echo '<SELECT name="dropdown">';
  foreach ($teacher as $t)
    echo "<OPTION>{$t['fname']}, {$t['lname']}</OPTION>\n";
  echo '</SELECT>';
  ?>
</body>
</html>

 

Any help or advice would be greatly appreciated.

Thanks in advance.

bascially your creating a form, so your need a button or some javascript,

 

then use $_GET or $_POST

 

ie

<form method="POST" action="page2.php">
<?php
echo '<SELECT name="dropdown">';
  foreach ($teacher as $t)
    echo "<OPTION>{$t['fname']}, {$t['lname']}</OPTION>\n";
  echo '</SELECT>';
  ?>
</form>

 

 

page2.php

<?php
echo $_POST['dropdown'];
?>

You need to put it into a form with a submit button. Like this.

 

<form method=POST name="userdata" action="your_next_page.php">
 <?php
 echo '<SELECT name="dropdown">';
 foreach ($teacher as $t)
   echo "<OPTION>{$t['fname']}, {$t['lname']}</OPTION>\n";
 echo '</SELECT>';
 ?>
 <input type="submit" value="Submit Info" onmouseover="this.className='buttonon'" onmouseout="this.className='button'" class="button"><br><br><br>
</form>

lol yeah and the button LMAO

 

revised

 


<form method="POST" action="page2.php">
<?php
echo '<SELECT name="dropdown">';
  foreach ($teacher as $t)
    echo "<OPTION>{$t['fname']}, {$t['lname']}</OPTION>\n";
  echo '</SELECT>';
  ?>
<input type="submit" name="submit" value="Page2">
</form>

 

thanx for point that out snowdog

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.