peterbrowne Posted September 23, 2008 Share Posted September 23, 2008 Hi I have a dynamic table which shows workshops for registration. If the user has registered for a workshop, then a button appears next to the workshop to allow unregistration. This is all working, except that if the user is registered in more than one workshop, then clicking the top unregister button, unregisters from the bottom workshop, not the workshop next to the button. Any help appreciated!! if(isset($_POST['unregister_type_1'])){ $workshop = $_POST['workshop_id_delete_type_1']; $query_unregister = "DELETE FROM registration WHERE registrant_id = '$registrant_id' AND workshop_id = '$workshop'"; $result_unregister = mysql_query($query_unregister, $connection) or die(mysql_error()); $query_update_seats = "UPDATE workshop SET seats_taken = seats_taken-1 WHERE workshop_id = '$workshop'"; $result_update_seats = mysql_query($query_update_seats, $connection) or die(mysql_error()); if($result_update_seats){ header('Location:register_workshops.php?success_unregister=true'); } } <td><?php if (in_array($row_type_1['workshop_id'], $registered)){ ?> <input type="submit" name="unregister_type_1" id="unregister_type_1" value="unregister" /> <input name="workshop_id_delete_type_1" type="hidden" value="<?php echo $row_type_1['workshop_id']; ?>" /><?php } ?></td> Quote Link to comment https://forums.phpfreaks.com/topic/125409-solved-dynamic-table-with-delete-button-for-each-row/ Share on other sites More sharing options...
.josh Posted September 23, 2008 Share Posted September 23, 2008 hmm...only thing i can think of is...are you using the same var as the input value in your form? That is, maybe the 'top' one and 'bottom' one are somehow holding the same id... Quote Link to comment https://forums.phpfreaks.com/topic/125409-solved-dynamic-table-with-delete-button-for-each-row/#findComment-648405 Share on other sites More sharing options...
DyslexicDog Posted September 23, 2008 Share Posted September 23, 2008 I agree with crayon, try creating a checkbox system then use a for each loop on your incoming array to test for deletion notices. You'll need to have different variable names for each workshop listing otherwise php will reuse the name of the variable and overwrite the previous value with the newest one. Quote Link to comment https://forums.phpfreaks.com/topic/125409-solved-dynamic-table-with-delete-button-for-each-row/#findComment-648408 Share on other sites More sharing options...
peterbrowne Posted September 23, 2008 Author Share Posted September 23, 2008 OK, thanks for the advice. I could not get it working with submit buttons to unregister for each workshop, so I just used checkboxes (which I was using for registration of each workshop anyway). FYI... if(isset($_POST['delete_type_1']) && isset($_POST['unregister_type_1'])){ foreach ($_POST['unregister_type_1'] as $workshopUnregister){ $query_unregister = "DELETE FROM registration WHERE registrant_id = '$registrant_id' AND workshop_id = '$workshopUnregister'"; $result_unregister = mysql_query($query_unregister, $connection) or die(mysql_error()); $query_update_seats = "UPDATE workshop SET seats_taken = seats_taken-1 WHERE workshop_id = '$workshopUnregister'"; $result_update_seats = mysql_query($query_update_seats, $connection) or die(mysql_error()); if($result_update_seats){ header('Location:register_workshops.php?success_unregister=true'); } } } And the relevant part of the form: <td> <div align="center"><?php if (in_array($row_type_1['workshop_id'], $registered)){ ?> <input type="checkbox" name="unregister_type_1[]" value="<?php echo $row_type_1['workshop_id']; ?>" /><?php } ?> </div></td> </tr> <?php } while ($row_type_1 = mysql_fetch_assoc($result_type_1)); ?> <tr> <td colspan="4"><span class="style8"><?php echo $workshop_type_1_message; ?></span></td> <td colspan="7"><div align="right"> <input type="submit" name="submit_type_1" id="submit_type_1" value="Register selected" /><?php if(!empty($registered)){ ?> <input type="submit" name="delete_type_1" id="delete_type_1" value="Unregister selected" /><?php } ?> </div> <div align="right"><span class="style8"><?php echo '<p>' . $registrationMessage_type_1; ?></span></div></td> </tr> </table> </form> Quote Link to comment https://forums.phpfreaks.com/topic/125409-solved-dynamic-table-with-delete-button-for-each-row/#findComment-648450 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.