0

I created a plugin which creates a database-table (wp_mediopay) and a widget in the admin dashboard. In this widget is a form, which should update an entry in the database table after being submitted.

I simply made it POST to saveentry.php. Then I created saveentry.php in the wp_admin folder:

$newaddress = $_POST["address"];
$table_name = "wp_mediopay";
global $wpdb;
$newaddress = array( 'address' => '$newaddress' );
$data_where = array( 'id' => 1);
$wpdb->update($table_name,$newaddress,$data_where);

but nothing happens. echo $newaddress works.

Weirdly, when I use this:

$myrows = $wpdb->get_results( "SELECT address FROM wp_mediopay WHERE id = 1" )
var_dump($myrows);

I get an error 500. When I do this in my plugin file it works fine.

0
$newaddress = array( 'address' => '$newaddress' ); // Incorrect

Is not the same as:

$newaddress = array( 'address' => $newaddress ); // Correct

And you have a missing ; at the end of:

$myrows = $wpdb->get_results( "SELECT address FROM wp_mediopay WHERE id = 1" )

And before the above line you must also have:

global $wpdb;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.