Jump to content

Recommended Posts

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!! ;D

 

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>

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.

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>

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.