1

I am trying to carry a variable over to disable.php which will then update a row in the database, all of this is within a wordpress plugin I am building. I cannot see why this won't work.

Heres my form

<form method='post' action='".plugins_url()."/myremovalsquote/inc/disable.php''>
  <input type='submit' name='".$_SESSION['id'] = $active_partner->partner_id."' class='button-primary' id='disable' value='Disable'/>
</form>

Heres my /disable.php

global $wpdb;

$id = $_SESSION["id"];

$wpdb->query("UPDATE partners SET active='no' WHERE partner_id='".$id."'");

header("Location: http://www.website.com/wp-admin/admin.php?page=my-plugin-settings");

This is the error I am getting, it seems that the variable from the session isn't being carried over to disable.php.

Brad Fletcher
  • 3,547
  • 3
  • 27
  • 42
  • Why not use a hidden input (``) ? – Jan Nov 17 '15 at 14:53
  • You edit adds "This is the error I am getting..." but I do not see the error. Did you forget to add it? Also, from what I can tell, this probably isn't working because wordpress doesn't use sessions by default. See [here](http://stackoverflow.com/questions/1441240/wordpress-session-management) and [here](http://wordpress.stackexchange.com/questions/32646/how-to-use-my-own-custom-session-value-in-wordpress) for my sources for that theory. – Don't Panic Nov 17 '15 at 18:09

3 Answers3

0

In addition to my comment, you could either use a hidden input field or store the values to be read and sent in the session alltogether. For the first solution:

<form method='post' action='/myremovalsquote/inc/disable.php'>
<input type="hidden" name="id_to_be_disabled" value="<?= $active_partner->partner_id; ?>">
  <input type='submit' class='button-primary' id='disable' value='Disable'/>
</form>

For the second solution just invoke the session with session_start(); and store the value in it. No need to fiddle around with the submit button name.

Jan
  • 42,290
  • 8
  • 54
  • 79
0

You have some errors in your form with name and value. Try this:

<form method='post' action='".plugins_url()."/myremovalsquote/inc/disable.php"'>
  <input type='submit' name='id' value='" . $active_partner->partner_id."' class='button-primary' id='disable' value='Disable'/>
</form>

And I also would prefer a hidden field here.

Joerg
  • 3,102
  • 2
  • 24
  • 30
-1

put session_start() on your /disable.php

Mindexperiment
  • 145
  • 1
  • 10