Jump to content

Recommended Posts

Hi,

I dont know what doing wrong

<form ...

<?php 

if($_POST['DeleteActor']) {
mysql_query( 'DELETE FROM `n_dramaact`
WHERE `n_dramaact_id` = "' . $_POST['n_dramaact_id'] . '"');
}

// Reload from dBase
$QueryDramActReturn = mysql_query( 'SELECT
	`n_dramaact`.`n_dramaact_id`,
	`n_dramaact`.`n_dramaact_dramid`,
	`n_dramaact`.`n_dramaact_dramact`,
	`n_actor`.`n_actor_id`,
	`n_actor`.`n_actor_fname`,
	`n_actor`.`n_actor_name`,
	`n_drama`.`n_drama_id`,
	`n_drama`.`n_drama_title`
FROM
	`n_dramaact`
Inner Join `n_actor` ON `n_actor`.`n_actor_id` = `n_dramaact`.`n_dramaact_dramact`
Inner Join `n_drama` ON `n_drama`.`n_drama_id` = `n_dramaact`.`n_dramaact_dramid`
WHERE `n_drama`.`n_drama_id` = "' . $REQUEST['n_drama_id'] . '"
ORDER BY `n_actor_fname` ASC
');

// Check query
if(!$QueryDramActReturn) { echo mysql_error(); exit; }

// Request query
while($REQUESTDR = mysql_fetch_array ($QueryDramActReturn)) {

?>
<div style="display: block; float: left; margin-left: 5px; margin-bottom: 5px;">
<?php echo $REQUESTDR['n_actor_fname'] . ' ' . $REQUESTDR['n_actor_name'];?> 
<input type="submit" name="DeleteActor" value="<-X" class="SubmitDelActor" />
<input type="hidden" name="n_dramaact_id" value="<?php echo $REQUESTDR['n_dramaact_id'];?>" />
</div>
<?php }?>

....</form>

I dont understand why when a push one of the listed DeleteActor submit button delete the last n_dramaact_id from table - every listed Submit button have the own (hidden) n_dramaact_id?

 

thanx in advanced

 

T

Link to comment
https://forums.phpfreaks.com/topic/210702-delete-dont-work/
Share on other sites

It'll be be better/easier if you displayed a checkbox next to each actor and one button for deleting the actors (at the end of the form)

<?php

....

// Request query
   while($REQUESTDR = mysql_fetch_array ($QueryDramActReturn)) {
      
?>
<div style="display: block; float: left; margin-left: 5px; margin-bottom: 5px;">
   <?php echo $REQUESTDR['n_actor_fname'] . ' ' . $REQUESTDR['n_actor_name'];?> 
   <input type="checbox" name="DeleteActor[]" value="<?php echo $REQUESTDR['n_dramaact_id'];?>" class="SubmitDelActor" />
</div>
<?php }?>
....
<input type="submit" name="DelectActorSubmit" value="Delete Selected" />
</form>

Now with the checkboxes in place, you can process all the selected checkboxs in one go using

 

if(isset($_POST['DeleteActorSubmit']))
{
    $actor_ids = implode(',', $_POST['DeleteActor']);

    $query = 'DELETE FROM `n_dramaact` WHERE `n_dramaact_id` IN('. $actor_ids .')';
    mysql_query($query);
}

Link to comment
https://forums.phpfreaks.com/topic/210702-delete-dont-work/#findComment-1099176
Share on other sites

That mean that I must to give unique id to submit button?

 

If you want to do it in the way you have started then you need to give each delete button a unique name that refers to the row you want to delete (names can be duplicated but ids must be unique anyway).

For example you could name the delete buttons "DeleteActor_~~" where the ~~ is the $REQUESTDR['n_dramaact_id']. When you receive the form your php script then loops through the $_REQUEST array until it finds a field with a name that starts with DeleteActor then get the id from the end of the name.

 

However the suggestion wildteen88 makes is very valid, probably easier to follow in code and also probably better if you expect people to delete multiple rows.

 

All the best

 

Keith

 

Link to comment
https://forums.phpfreaks.com/topic/210702-delete-dont-work/#findComment-1099225
Share on other sites

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.