William Bruijntjes William Bruijntjes - 6 months ago 21
jQuery Question

Send form when with mysql_fetch_array while loop CLOSED

I have got a while loop that runs through all the records of the database printing them on a table. Now i also have some checkboxes within that very loop that I want to use to submit a form when clicked. Now when I click the checkbox it will indeed submit the form thanks to a Jquery script I found, BUT whenever i submit it it submits with the ID of the first record of the table.This Image

shows the table, as you see the first record has ID 34. Now every checkbox I click will send the $id 34.

This does not happen with normal submit buttons.

Is there a way I can submit with the individual userID's



while ($openResInfo = mysql_fetch_array($openResQuery))
{
$id = $openResInfo[0];
$complete = $openResInfo[7];

?>
<form id='resComplete' action='dashboard_openReserveringen_PHP.php' method='GET'>
<?php
echo "<input type='hidden' name='userID' value='$id'>";
?>
<input type="hidden" name="complete" value="0" >
<input id='complete' type='checkbox' name='complete' value='1' onchange='$("#resComplete").submit();' <?php if($complete == 1){echo "checked";}?>>

</form>





I'm sorry if i'm not very clear with the explanation it is quite hard to explain this situation. Thank you guys!

Answer

Probably your problem is that you are submiting the same form always and its because you create a form for each row but it has the same id

For you the easy way is to put each form with the id cointaining the unique value of the row and doing submit with that.

Something like this

while ($openResInfo = mysql_fetch_array($openResQuery))
            {
                $id = $openResInfo[0];
                $complete = $openResInfo[7];

            ?>
                    <form id='resComplete_<?php echo $id; ?>' action='dashboard_openReserveringen_PHP.php' method='GET'>
                        <?php
                        echo "<input type='hidden' name='userID' value='$id'>";
                        ?>                   
                        <input type="hidden" name="complete" value="0" >
                        <input id='complete' type='checkbox' name='complete' value='1' onchange='$("#resComplete_<?php echo $id; ?>").submit();' <?php if($complete == 1){echo "checked";}?>>

                    </form>
Comments