Page 1 of 1

Value from listbox

Posted: Thu Oct 01, 2009 3:46 pm
by budatlitho
Hello:
I've been struggling with how to retrieve a value from the user's selection from a dynamic listbox. What I want to retrieve is the value of $row['id'] once the user makes their selection from the firstname and lastname list. I've tried $_POST['memberid'] and most variations, but cannot seem to hit on the right syntax.

Here's my code:

<?php
if<?php require_once('Connections/ReunionServer.php'); ?> (!isset($_SESSION)) {//start session if not already started
session_start();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?
mysql_select_db($database_ReunionServer, $ReunionServer);
//make query to database
$query_Recordset1 ="SELECT firstname, lastname, id FROM reunion_members ORDER BY lastname";
$Recordset1 = mysql_query($query_Recordset1, $ReunionServer) or die(mysql_error());
echo '<select name="memberid">';
while ($row = mysql_fetch_array($Recordset1)) {
echo '<option value="',$row['id'],'">',$row['firstname'], ' ', $row['lastname'],'</option>';
}
echo '</select>';
?>

<p>What I want to see is: $row['id'] </p>
</body>
</html>
<?PHP
mysql_free_result($Recordset1);
?>

Re: Value from listbox

Posted: Thu Oct 01, 2009 6:41 pm
by mybikeisgreen
I don't see a <form method="post"> tag anywhere. Without the <form> tag nothing gets submitted to the server, and method="post" is required if you want them in a $_POST array.

Re: Value from listbox

Posted: Thu Oct 01, 2009 6:54 pm
by budatlitho
I should explain what I'm trying to do, eh? (grin)
I want to present a list of names to choose from, and after the choice to get a record from a different table and display it.
I don't have anything to "post" to a server, therefor there's no <form method = "post"> tag.

Maybe I'm attacking this the wrong way? Can I get the value of $row['id'] into a session variable and then open another page?
THANKS for the quick response.

Re: Value from listbox

Posted: Thu Oct 01, 2009 7:01 pm
by mybikeisgreen
I don't see how you can avoid using a <form> If you don't want to use method="post" then use method="get".

Try this

<form method="get" action="page2.php">
... [your code here]
</form>

Then on page2.php you can retrieve the id with

$_GET['memberid']