Hello all
OK I am really new to PHP, been playing with it now for a week and spent the weekend trying to get around a problem - spent a long time on it and out of desperation I am having to ask for help. I hope some kind soul out there can help..
Ok I have a page with an array driven dropdown for selecting a football player position (it is for a fantasy league auction application) - one of 5 options. The PHP then runs a concatenated SQL incorporating this result to generate a list of all players who play that position from a database. This all works fine....
The problem I have is getting the second select to pick up the variable 'player_no' from the database - first off here is the script
<?php require_once("includes/connection.php"); ?>
<?php require_once("includes/header.php"); ?>
<form method="post">
<select name="pname">
<?php
$category = array(
1=> "GK",
2=> "FB",
3=> "CB",
4=> "MF",
5=> "ST",
);
$category = str_replace(" ", " ", $category);
echo "Player Position:" . '<SELECT name=category>';
foreach ($category as $key => $value)
{
echo '<OPTION value='.$value.'> '.$value.'';
}
echo '</select>';
$option = $_POST['pname'];
?>
<input type=submit value="Select Position">
<?php
$query = "SELECT * FROM players_1 where player_pos LIKE '".$option."'"." and player_selected like '0';" ;
$result = mysql_query ($query);
echo "<select name=sname value=''>Player</option>";
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[player_pos]>$nt[player_no] $nt[player_name] $nt[player_club]</option>";
}
echo "</select>";
?>
<input type=submit value="Select Player">
<br />
<?php
$option2 = $_POST['sname'][$nt['player_no']]; //<-- this is where the problem is
echo $option2;
?>
<?php require_once("includes/footer.php"); ?>
For some reason the code returns for $option2 just the letter 'G' or 'F' (first letter of the player position (the echo is obviously there for just a test for now)
What I need it to do is return a value from the database (player_no) associate to the selected player, then run an update to set a flag for that player to assign him to a particular team (once I get past this there will be another drop down/automated selection for the football team)
I hope the above makes sense and I would really appreciate any help anyone can give us
Cheers
Wayne