[wp-hackers] Delete Row - Refreshes Page but not DB

BenderisGreat greglancaster71 at gmail.com
Wed Sep 25 17:00:18 UTC 2013


The following code I wrote to perform two functions. Delete a row matching
the the row[id] and to also erase the associated attachment post. It
functions - The code shows the delete button in every row, and when pressed
the row is deleted. However after pressing delete the page is refreshed (not
sure why, I dont have any onclick or onsubmit events set) and the row
remains until a manual refresh is performed. Need a little assistance
figuring why;

<?php      
if (isset($_POST['id'])) {
$id = $_POST['id'];
if (isset($_POST['deleteItem'])) {
get_delete_post_link( get_the_ID($row['file']));
$qry = "DELETE FROM wp_jo_plugin_options WHERE id = ".$id."";
$jo_remove_row = $wpdb->query($qry);
}    
} 
?>


Here is the code responsible for showing the table.

<?php 
$jo_max_rows = get_option( 'jo_plugin_options'); 
$result_array = $wpdb->get_results('SELECT * FROM '. $wpdb->prefix .
jo_plugin_options .' WHERE user_id = '. $userid .' ORDER BY date DESC',
ARRAY_A);
$i = 0;
$limit = $jo_max_rows['jo_max_records'];
$count = count($result_array);
while ($i < $limit && $i < $count) 
{
$row = $result_array[$i];
$jo_pic_icon = wp_get_attachment_url( $row['file'] ); 
?>




<?php echo $row['date']; ?>
<?php echo $row['length'] . '' . $selected ?>

<?php echo $row['ground'] . '' . $selected ?>

<?php $del_hide = (isset($table_fields['jo_checkbox_del']));
if (!$del_hide) { ?>



<form method="post" action="" />
    <input type="hidden" name="id" value="<?php
echo $row['id']; ?>" />
    <button type="submit" name="deleteItem" value="delete"
class=""></button>
    <?php } else { }; ?>
</form>


<?php if(!empty($row['file'])) { ?>
<a href="<?php echo $jo_pic_icon; ?>"> 
<? } else { }; ?>


<?php 
    ++$i; }
?>



--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/Delete-Row-Refreshes-Page-but-not-DB-tp42392.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.


More information about the wp-hackers mailing list