Jump to content

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

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.