Discussion:
Delete Row After Submit - Undefined
BenderisGreat
2013-10-11 20:13:57 UTC
Permalink
I have an issue that is apparently ongoing that I didnt realize until I
turned on debug mode. I have a delete button on every row of a table, and
when clicked it grabs the row ID and erases that information. However it
also grabs a field from the picture row (its a post id for the image
attachment) and attempts to delete that as well.

<?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);
}
}
?>



The problem is that its telling me that $row is an undefined variable. If I
put it inside the while loop it works, but then the page requires a refresh
after deletion because the table is loaded before the delete code is. Is
there any solution to this? Possible to redefine a variable upwards in the
document order possibily?



--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/Delete-Row-After-Submit-Undefined-tp42521.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
J.D. Grimes
2013-10-11 20:21:47 UTC
Permalink
What are you expecting the $row variable to be? Where are you expecting it to come from?
Post by BenderisGreat
I have an issue that is apparently ongoing that I didnt realize until I
turned on debug mode. I have a delete button on every row of a table, and
when clicked it grabs the row ID and erases that information. However it
also grabs a field from the picture row (its a post id for the image
attachment) and attempts to delete that as well.
<?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);
}
}
?>
The problem is that its telling me that $row is an undefined variable. If I
put it inside the while loop it works, but then the page requires a refresh
after deletion because the table is loaded before the delete code is. Is
there any solution to this? Possible to redefine a variable upwards in the
document order possibily?
--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/Delete-Row-After-Submit-Undefined-tp42521.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Nikola Nikolov
2013-10-11 20:22:43 UTC
Permalink
I don't think you need to call the get_delete_post_link() function.

Since you're deleting the entry with $wpdb->query() . Just remove the
get_delete_post_link() line and your code should work just fine :)

Nikola


On Fri, Oct 11, 2013 at 11:13 PM, BenderisGreat
Post by BenderisGreat
I have an issue that is apparently ongoing that I didnt realize until I
turned on debug mode. I have a delete button on every row of a table, and
when clicked it grabs the row ID and erases that information. However it
also grabs a field from the picture row (its a post id for the image
attachment) and attempts to delete that as well.
<?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);
}
}
?>
The problem is that its telling me that $row is an undefined variable. If I
put it inside the while loop it works, but then the page requires a refresh
after deletion because the table is loaded before the delete code is. Is
there any solution to this? Possible to redefine a variable upwards in the
document order possibily?
--
http://wordpress-hackers.1065353.n5.nabble.com/Delete-Row-After-Submit-Undefined-tp42521.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
Gregory Lancaster
2013-10-11 20:25:52 UTC
Permalink
the delete post link is because I am storing this other information in a
separate table. So I have to delete it from that table, and then grab the
attachmend-id i stored in the row and call that delete function to remove
it from the wordpress media library.
Post by Nikola Nikolov
I don't think you need to call the get_delete_post_link() function.
Since you're deleting the entry with $wpdb->query() . Just remove the
get_delete_post_link() line and your code should work just fine :)
Nikola
On Fri, Oct 11, 2013 at 11:13 PM, BenderisGreat
Post by BenderisGreat
I have an issue that is apparently ongoing that I didnt realize until I
turned on debug mode. I have a delete button on every row of a table,
and
Post by BenderisGreat
when clicked it grabs the row ID and erases that information. However it
also grabs a field from the picture row (its a post id for the image
attachment) and attempts to delete that as well.
<?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);
}
}
?>
The problem is that its telling me that $row is an undefined variable.
If
Post by BenderisGreat
I
put it inside the while loop it works, but then the page requires a
refresh
Post by BenderisGreat
after deletion because the table is loaded before the delete code is. Is
there any solution to this? Possible to redefine a variable upwards in
the
Post by BenderisGreat
document order possibily?
--
http://wordpress-hackers.1065353.n5.nabble.com/Delete-Row-After-Submit-Undefined-tp42521.html
Post by BenderisGreat
Sent from the Wordpress Hackers mailing list archive at Nabble.com.
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
http://lists.automattic.com/mailman/listinfo/wp-hackers
J.D. Grimes
2013-10-12 14:00:48 UTC
Permalink
Post by BenderisGreat
<?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.""; // ****** <- HERE *******
$jo_remove_row = $wpdb->query($qry);
}
}
?>
You should be using $wpdb->delete() (http://codex.wordpress.org/Class_Reference/wpdb#DELETE_Rows), and you should really also be using nonces (http://codex.wordpress.org/WordPress_Nonces).

Also, I don't understand why you are calling get_delete_post_link(). All that it does is return the URL that a user can visit to delete a post. If you want to delete the attachment, call wp_delete_post() with the attachment ID (http://codex.wordpress.org/Function_Reference/wp_delete_post).

--J.D.

Loading...