0

So basically I have the following code:

 if(isset($_GET['deleteid'])) {
 $delete = $_GET['deleteid'];
 $denyrequest = "DELETE FROM wp_refundrequests WHERE request_id = $delete";
 }

$requests = $wpdb->get_results("SELECT * FROM wp_refundrequests", ARRAY_A);

foreach ($requests as $row) {
echo "<li>" . $row['product_name'] . " " .
"<a href='admin-page?deleteid=" . $row['request_id'] . "'>Deny</a></li>" .
"<a href='admin-page?acceptid=" . $row['request_id'] . "'>Accept</a></li>";
}

Where if users clicks either Deny or Accept on the list of items, it adds a parameter to the URL and with that parameter, deletes the wanted row from the database. Currently however after pressing on any of the Deny (Or Accept) links, the result is the following, where there is a slash before the parameter:

Problematic URL

I have done the same kind of code to delete DB data using a list once before, but it was without WordPress and I had no problems by just linking the file normally. The deletion doesn't go through and I'm assuming that this is the cause.

Basically at the moment nothing happens other than the URL looks like that.

Thank you in advance!

Puppe
  • 112
  • 3
  • 15
  • 2
    Your `$denyrequest` is just a string that doesn't do anything, you would have to pass it on to `$wpdb->query` or something. You should also use as prepared statement instead of directly inserting the GET variable into your query, in my opinion. As to your question, here's [something](https://stackoverflow.com/questions/8558234/remove-trailing-slash-using-htaccess-in-wordpress) that might help, but it involves editing htaccess. – Hans Oct 02 '18 at 07:51
  • @Michael You're actually so right, I feel so dumb right now. Thanks! – Puppe Oct 02 '18 at 08:11

1 Answers1

0

Like comment stated, you do not take any delete action, just prepare a string Try adding something like:

$wpdb->delete( "wp_refundrequests", array( 'request_id' => 1 );

to your 1st if:

 if(isset($_GET['deleteid'])) {
 $delete = $_GET['deleteid'];
 $wpdb->delete( "wp_refundrequests", array( 'request_id' => 1 ));
 }

reference

Guy Louzon
  • 1,175
  • 9
  • 19