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>
<legend>Cabinets:</legend>
<?php for ($i = 0; $i < count($cabinetoptions); $i++): ?>
<div>
<label for="cabinets<?php echo $i; ?>">
<input type="checkbox" name="cabinetoptions[]" id="cabinet<?php echo $i; ?>"
value="
<?php htmlout($cabinetoptions[$i][‘id’]); ?>"
<?php if ($cabinetoptions[$i][‘selected’])
{
echo ' checked="checked"';
}
?>/>
</label>:
<?php htmlout($cabinetoptions[$i]['cabinet']); ?>
</div>
<?php endfor; ?>
</fieldset>
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: :wink:](https://global.discourse-cdn.com/sitepoint/original/3X/0/2/02a1faf5c304c9786b0783439531204d9d204d04.gif?v=12)
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.