Issue with code in Firefox 4

I’m hoping someone can help me. I’m new to php and mysql. My current issue is that my check box list works great in firefox 3.6. When I use either Firefox 4 or Chrome my checkbox list’s erase all data associated in them when the form is updated. I’ve noticed that my search system when looking for something associated in the check box is also not working.

Any help would be much appreciated.

php code.

$cabinetid = mysqli_insert_id($link);

if(isset($_POST[‘cabinetoptions’]))
{
foreach ($_POST[‘cabinetoption’] as $cabinets)
{
$cabinetcategoryid = mysqli_real_escape_string($link, $cabinets);
$sql = “INSERT INTO cabinetcategories SET
cabinetid=‘$cabinetid’,
cabinetcategoryid=‘$cabinetcategoryid’”;
if (!mysqli_query($link, $sql))
{
$error = ‘Error assigning selected cabinet.’;
include ‘error.html.php’;
exit();
}
}
}

html code

<fieldset>

		&lt;legend&gt;Cabinets:&lt;/legend&gt;

			&lt;?php for ($i = 0; $i &lt; count($cabinetoptions); $i++): ?&gt;

			&lt;div&gt;
				&lt;label for="cabinets&lt;?php echo $i; ?&gt;"&gt;
				&lt;input type="checkbox" name="cabinetoptions[]" id="cabinet&lt;?php echo $i; ?&gt;"

value="
<?php htmlout($cabinetoptions[$i][‘id’]); ?>"
<?php if ($cabinetoptions[$i][‘selected’])

				{
					echo ' checked="checked"';
				}
				?&gt;/&gt;
				
				&lt;/label&gt;:
				&lt;?php htmlout($cabinetoptions[$i]['cabinet']); ?&gt;

			&lt;/div&gt;
			&lt;?php endfor; ?&gt;

	&lt;/fieldset&gt;

Try the following, replace

?>/>

with

?> />

I cringe whenever I see php nested in html.

Gave that a try and it didn’t work. I’m not sure if it helps in the troubleshooting but if I choose one item in the check box I don’t get the error however it doesn’t actually save the change. If I select check more than one item it gives me the error. Well it gives me the error message I created. I cannot remember the code to display the actual error created.

How else does one show php variables in a html page? I am new to this. If there is a better way I’ll give it a try.

My untested guess is the whitespace is messing things up. i.e.

<input type="checkbox" name="cabinetoptions[]" id="cabinet<?php echo $i; ?>"
value="
<?php htmlout($cabinetoptions[$i]['id']); ?>"
<?php if ($cabinetoptions[$i]['selected'])

{
echo ' checked="checked"';
}
?>/>

would result in markup like

<input type="checkbox" name="cabinetoptions[]" id="cabinet1"
value="
123"



checked="checked"

/>

If you look in view-source do you see something like that?

It looks very similar to that. What should the proper spacing be, something like this?

<?php if ($cabinetoptions[$i][‘selected’]){echo ’ checked=“checked” ';}?> />

That looks like that should be good for “checked”.

I think if you do something similar for “value” you just may be all set.

I take it you’re beginning to understand thepanos’ “cringe” comment by now :wink:

It works, but things can get messy quickly and be a bear to troubleshoot.

Maybe you could try heredoc syntax? I like to use it anytime I start getting a bunch of in-and-out of PHP’s

Well it looks like my manager wants to change the database to work with some .net systems. So I’m going to be changing the forms.

Thanks for all the help on this issue.