Changing dropdown based on selected radio button

Hi all,

I’ve been struggling with this piece of code for a good couple of days now. What I’m trying to do it change the options of a drop down list depending on which radio button is selected. What I’m having trouble with is passing the variable from the radio button to form link to read. Here’s the code below:


<?php
$connection = mysql_connect("server","user","pass");
$db=mysql_select_db("db", $connection);

$furniture = "SELECT furniture FROM items";
$sql = mysql_query($furniture) or die(mysql_error());
while ($row = mysql_fetch_array($sql))
{
	echo "<input type=\\"radio\\" name=\\"web\\" value='".$row['furniture']."'>".$row['furniture']."</input>";
}

$user = $_POST['web'];//The problem??
$dir = $user."/upload";
echo "<br /><select name=\\"up\\">";

if(file_exists($dir))
{
	if($dh=opendir($dir))//Opening directory
	{
		if(($dhf = scandir($dir)) && (count($dhf) == 2))
		{
			echo "<option value=\\"empty\\">Directory is empty!</option>";
		}
		else
		{	
			while (($sd = (readdir($dh))) !== false)//while the directory being read is 
			{
				if($sd != "." && $sd != "..")
				{
					echo "<option value='".$sd."'>".$sd."</option>";
				}
			}
		}
	}
}
echo "</select>";

echo"<br />If your can find the type of furniture you are looking for create a new one:";
echo"<br /><input type=\\"text\\" name=\\"newFolder\\" />";

?>

Any help would be apprieciated. Thanks,

Stow

It comes up as NULL but I think that’s because the radio button hasn’t been set at the start…

it’s NULL after you select a radio and post the form? or am i misunderstanding what you’re trying to do?

sorry I’m not being clear. Before I select a radio button the output of var_dump($_POST[‘web’]) is NULL. After I select a radio button the output is still NULL

right before you set your $user var, you should do a var_dump($_POST[‘web’]) to see whats in that variable, and make sure it’s being passed

sorry I forgot this code that it links to:


<!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>Upload File</title>
</head>

<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="104857600" />
File:<input type="file" name="file" /><br />
<?php include 'form.php'; ?><br /><!--lists furniture depending on type-->
<input type="submit" name="submit" />
</form>

</body>
</html>


The above is a php file that is used to upload information to the furnitures directorys it is unfinished. However, the way in which I want to combine this code and the previous is all done using the include ‘form.php’… I left these codes separate for database security

where’s your form tag? does it have method=“POST” in it?