Newbie question - set value of list box to a variable...

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have some code that populates a list box from a database.  I am
trying to assign the value of the list box to a variable when the user
clicks on a button.  For some reason, my code does not set the
variable.  Any ideas?  Here is the code I am using:


$dom = new DOMDocument("1.0");
$node = $dom->createElement("markers");
$parnode = $dom->appendChild($node);

$connection=mysql_connect (localhost, $username, $password);
if (!$connection) { die('Not connected : ' . mysql_error());}

$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());

$query="SELECT fullname FROM deceased ORDER BY fullname";
$result = mysql_query ($query);
echo "<select name=\"Deceased\">";// Start list box

echo "<option value=$nt[fullname]>$nt[fullname]</option>";

echo "</select>";// Closing of list box

$select = $_POST['select'];
$chooser = $_POST['Deceased'];


<form action="testphp.php5" method="POST" >
<p><input type="Submit" name="Select" value="select" /></p>




Re: Newbie question - set value of list box to a variable...

Quoted text here. Click to load it

Although the echo inside the while loop /might/ work, it isn't really
correct.  If you enable error reporting and display errors you'll see
what I mean.  You need to quote literal array keys as well as HTML
attribute values.  Additionally you should escape any special
characters.  There are lot's of ways to do that, and here's one of

echo '<option value="' . htmlspecialchars($nt['fullname']) . '">' .
htmlspecialchars($nt['fullname']) . '</option>';

That's not your main problem, though.

Quoted text here. Click to load it

Your select list is outside of the <form> element.  When a form is
submitted, only those elements that are inside the form get sent.

Re: Newbie question - set value of list box to a variable...

Mapper99 wrote:
Quoted text here. Click to load it

Additionally, your $_POST variable won't be set in this script.  It will
be set in testphp.php5.

This script will be completely finished before the page is displayed on
the user's computer.

If this is testphp.php5, it won't be set the first time through, but
will be the second.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.

Site Timeline