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!

Select option box values

Status
Not open for further replies.

dagoat10

Programmer
Jun 3, 2010
74
US
I am having the hardest time retriving the value of my selection box.

Here is my selection code:
Code:
echo "<form name='Set' method='post' action='Set_Team.php'>";
echo "<td>";
echo "<table border = '0'>";
while($row = mysql_fetch_array($data))
{
    $ID = $row['ID'];
    echo "<tr>";
    echo "<td>";
    echo $row['Player'];
    echo "</td>";
    echo "<td>";
    echo "<select name='Status'>";

    echo $row['Start_Sit'];

    if($row['Start_Sit'] == "Start")
    {
        echo "<option value='Start' selected>Start</option>";
        echo "<option value='Sit'>Sit</option>";
    }
    if($row['Start_Sit'] == "Sit")
    {
        echo "<option value='Sit' selected>Sit</option>";
        echo "<option value='Start'>Start</option>";
    }
    echo "</select>";
    echo "</td>";
    echo "</tr>";
}

echo "</table>";
echo "<center>";
echo "<input type='submit' name='Set' value='Set Players' />";
echo "</td>";
echo "</tr>";
echo "</form>";

Then i try to send it to my database and it does not set the update, the values don't change.

Code:
$setquery="SELECT * from $TeamName";
$setdata=mysql_query($setquery);

while($setrow = mysql_fetch_array($setdata))
{
    $Set=$setrow['ID'];
    //echo $Set;
    //echo $_POST[$Set];
    $setquery2 = "UPDATE $TeamName set Start_Sit=$_POST[Status] where ID='Donovan McNabb'";
    mysql_query($setquery2);
}

is it my select box or not pulling the option. I tried a foreach loop but that did not work.
 
the correct attribute for an <option> element to be selected is
Code:
selected="selected"

the values for each option element are string. however you are trying to insert them into your database as non-string literals. strings MUST be enquoted

Code:
UPDATE $TeamName set Start_Sit='$_POST[Status]' where ID='Donovan McNabb';

you are also trusting user supplied data in a query. this is never a good idea. you should
1. cleanse the value of POST['Status'] before using it
2. ensure that the value is one of the two permitted values
3. escape the value as good measure before enquoting it for use in the sql query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top