Jump to content

[SOLVED] sticky checkboxes


nomis

Recommended Posts

Hi, I'm sorry if this has been answered elsewhere, but I'm having some trouble keeping some checkboxes that were called as an array to stay sticky if the form errs on other required fields.

 

Here's what I have have:

 

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<table width=500 border=0 cellpadding=5>
<tr>
<td valign="top"><label for "person_type_code">Person Type:</label> </td>
<td><?php 
$r = mysqli_query($dbc, 'select * from person_type order by person_type');
while ($row = mysqli_fetch_array($r)) {
echo '<input type="checkbox" id="person_type" name="person_type_code[]" ' ;
echo 'value="' . $row[0] .'"';
    if (isset($_POST['person_type_code'])) { echo ' checked="checked"';
	} 
    echo '> ' . $row[1] . '<br />'; 
}
?> </td> 

 

This is unfortunately making EVERY checkbox show as checked, not just the ones that the user has selected.  I need this form to come back with only the fields that a person has selected (one or more... a person may have many types) to appear checked.

 

Can someone see what is wrong with my code?  I have tried using  $row in place of $_POST['person_type_code'] but it has the same effect. 

 

Thanks!

Link to comment
Share on other sites

  • 2 years later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.