Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Variables From Selects

Status
Not open for further replies.

Louth

Programmer
Jan 21, 2004
16
EU
Could anybody help me with the following problem. I am trying to pass a value from a selectbox to a url which refreshes the page. I am having a problem passing the value. The code is set out as follows:

if(!isset($skill))
{
<table cellspacing='0' cellpadding='3' width='90%' border='0'>
<form method=post action=access.php?page=trainers/trainer_browse&skill=$skill>

<tr><td><p>Please choose a training skill from the list below</p></td></tr>

<tr><td>
<select name='skill' value='skill' type='text'>";

$skills = mysql_query("select * from db_trainings");

while ($result = mysql_fetch_array($skills))
{
$skill_name=$result['training_name'];
echo "<option>$skill_name</option>";
}

echo "</td></tr><tr><td><input value='GO' type='submit'>
</td></tr></table>
</form><br>";
}

When the button is clicked the URL is executed but the $skill value is not being passed on. If anybody can help with this problem or suggest an alternative approach please let me know.
 
it's because you have register globals set to off... use $_POST["skill"] instead of $skill
 
I have tried this but it is giving me errors. How exactly would you modify the existing code?
 
Code:
<?
if(!isset($skill))
{
echo "<table cellspacing='0' cellpadding='3' width='90%' border='0'>
        <form method=post action=access.php?page=trainers/trainer_browse>

<tr><td><p>Please choose a training skill from the list below</p></td></tr>

<tr><td>
<select name='skill' value='skill' type='text'>";

$skills = mysql_query("select * from db_trainings");

while ($result = mysql_fetch_array($skills))
{
       $skill_name=$result['training_name'];
       echo "<option value='" . $skill_name . "'>$skill_name</option>";
}

echo "</td></tr><tr><td><input value='GO' type='submit'>
</td></tr></table>
</form><br>";
}
?>

this is because I gather you need the value of the select, not the one that you used to pass as a parameter in URL.

if you still have problems, post back and mention the errors (a better description of what you indended your code to do would be welcomed)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top