PHP variables showing as plain text

This is a strange issue (for me, at least) that I’ve never encountered before. Below is a simple code to create a table with form checkboxes, each one labeled by my sql column names on fields 5-24.

Everything works fine, the table is created, and its functionality does roughly what I want it to do. The issue I’m having is this:

[php]
echo ’
';
[/php]

For whatever reason, the $var shows as plain text when I run this script in any browser. Viewing the page source, all 19 of my checkboxes are value="$var", and the form submit button ($aWidget[$i]) spits “$var” right back at me for each checkbox that’s selected. This issue isn’t appearing anywhere else on my webpage; just seems to be within the foreach loop that variables aren’t being defined the way they should be. Is there any quick fix for this?

Thanks in advance.

[php]$createSearchTable = array(5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24);

echo ’

'; echo ' '; echo ' '; echo " ";
    foreach ($createSearchTable as $var)
	{
		echo '
		<td width="25" height="25" align="center" valign="center">';
		if ( $var == 24 )
		{
		  echo '
		  <input type="checkbox" name="sAll" value="All"/>';
	    }
	    else
	    {
		  echo '
		  <input type="checkbox" name="formWidget[]" value="$var" />';
		}
		echo '  
		</td>';

		echo '
	    <td width="85" height="25" align="left" valign="center">';
	    if ( $var == 24 )
	    {
		    echo '
		    <input type="submit" name="formSubmit" value="Submit" />';

$aWidget = $_POST[‘formWidget’];
if(empty($aWidget))
{
echo(“You didn’t select any widgets.”);
}
else
{
$N = count($aWidget);
echo("You selected $N widget(s): ");
for($i=0; $i < $N; $i++)
{
echo ‘’ . $aWidget[$i] . ‘’;
}
}

	    }
	    else
	    {
			echo '' . mysql_field_name($query, $var) . '';
			    
		}
		echo '
		</td>';
		
		if ( $var == 9 or $var == 14 or $var == 19 )
		{
	  echo "
	  </tr>
	  <tr>";
		}
	
	}


  echo "
  </tr>";
echo "
</table>";

echo "

"; echo " ";[/php]

Just stumbled into a ‘quick fix’ to my own issue after a bit of experimentation, if anyone was interested.

Working code:
[php]echo ’
<input type=“checkbox” name=“formWidget[]” value="’;
echo “$var”;
echo ‘" />’;[/php]

Non-working code:
[php]echo ’
';[/php]

This is just downright sloppy looking, but it works for now. I was never aware that single quotations broke php code, but I’m still relatively new to this stuff.

Sponsor our Newsletter | Privacy Policy | Terms of Service