Forum Moderators: coopster

Message Too Old, No Replies

PHP MySql Database loop receiving checked box item state

Help with MySql checked box loops

         

MRInc

4:49 pm on Mar 10, 2012 (gmt 0)

10+ Year Member



Hello

Please help me.
I am trying to get my php to get the checked list box state in a loop.
Please tell me what I have done wrong.


mysql_connect($mysql_host,$mysql_user,$mysql_password);
if(mysql_select_db($mysql_database))
{
{
$query2 = "SELECT * FROM PrefSkinRange";
$result2=mysql_query($query2);
$count2=mysql_numrows($result2);
$code2;
for($i = 0 ; $i < $count2 ; $i++)
{
$str=mysql_result($result2,$i,"PrefSkinRange");
$nstr = str_replace(" ","",$str);
$nstr = strtolower($nstr);
$ssr = "NO";
if(isset($_POST['$nstr']) && $_POST['$nstr'] == 'OK')
{
***** When checking information in the loop this never triggers, but when checking the checked box that was not in the loop it works.

$ssr = "YES";
}
$code2 = "$code2 <input type='checkbox' name='$nstr' value='OK'><FONT COLOR='FFFFFF'>$nstr:$ssr</font><BR>";
}
$ssr = "NO";
if(isset($_POST['ONE']) && $_POST['ONE'] == 'OK')
{
$ssr = "YES";
}
echo "<form action='page6.php' method='post'>
<input type='checkbox' name='ONE' value='OK'><FONT COLOR='FFFFFF'>ONE:$ssr</font><br>
<input type='hidden' value='1' name='run' />
$code2
<input type='submit' value='TEST' />";
}
}
else
{
echo "ERROR DATABASE";
}


All help is greatly appreciated.

Thanks

eelixduppy

12:52 pm on Mar 15, 2012 (gmt 0)



$_POST['$nstr']


This is the culprit. You cannot use apostrophes here because they will take $nstr as a string literal instead of evaluating it as a variable. Remove the quotes:

$_POST[$nstr]