web_master Posted August 14, 2010 Share Posted August 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/210702-delete-dont-work/ Share on other sites More sharing options...
kickstart Posted August 14, 2010 Share Posted August 14, 2010 Hi You appear to have a delete button per line but nothing on the delete button to specify which line is deleted. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/210702-delete-dont-work/#findComment-1099140 Share on other sites More sharing options...
web_master Posted August 14, 2010 Author Share Posted August 14, 2010 Hi You appear to have a delete button per line but nothing on the delete button to specify which line is deleted. All the best Keith That mean that I must to give unique id to submit button? T Quote Link to comment https://forums.phpfreaks.com/topic/210702-delete-dont-work/#findComment-1099141 Share on other sites More sharing options...
wildteen88 Posted August 14, 2010 Share Posted August 14, 2010 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); } Quote Link to comment https://forums.phpfreaks.com/topic/210702-delete-dont-work/#findComment-1099176 Share on other sites More sharing options...
kickstart Posted August 14, 2010 Share Posted August 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/210702-delete-dont-work/#findComment-1099225 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.