Author |
Message |
compstudent
|
Posted: Sat Apr 23, 2011 10:29 am Post subject: unidentified index |
|
|
Hi,
I have this code
for ($i = 1; $i<4; $i++)
{
$game = "game_$i";
$radio = "radio_$i";
$col = $_POST['$radio']; //Error is here
$username = $_SESSION['username']; ........
And it goes on to save names in a database.
The form that it is from is this:
echo "<form id='predict' action='savePredict.php' method='post'>";
for ($i=1; $i<4;$i++)
{
$gameid = "game_$i";
$name = "radio_$i";
$get = mysql_query("SELECT*FROM $gameid WHERE id='1'");
$rows = mysql_fetch_assoc($get);
echo "<div class='game'>";
echo "<label class='team1'>$rows[team1] <input type='radio' name='$name' value='team1'/></label>";
echo "<label class='team2'><input type='radio' name='$name' value='team2'/>$rows[team2] </label><br/>";
$get = mysql_query("SELECT*FROM $gameid WHERE id='2'");
$rows = mysql_fetch_assoc($get);
echo "<label class='bet1'>$rows[team1]</label><label class='bet2'>$rows[team2]</label><br/><br/>";
echo "<label class='tie'>Tie<input type='radio' name='$name' value='tie'/> </label><br/>";
echo "</div>";
}
I always get the error unidentified index $radio whenever i try to submit data. I don't know too much about radio buttons and using them with $_POST in php - but I can't find where i am going wrong.
Thanks |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Amailer
|
|
|
|
|
compstudent
|
Posted: Mon Apr 25, 2011 5:16 pm Post subject: Re: unidentified index |
|
|
Thanks....Good to know. |
|
|
|
|
|
yoursecretninja
|
Posted: Tue Apr 26, 2011 4:53 pm Post subject: RE:unidentified index |
|
|
You only need to put the double quotes when you want to evaluate a variable inside a string. In your example with the key you can ommit the quotes.
$col = $_POST[$radio] is just fine. |
|
|
|
|
|
|