in WordPress, I have a custom table in which I want to store settings for use in a plugin. The code for the admin page of the plugin, contains a form and prior to displaying the form, I access the database and retrieve the present items.

The problem is, when I click on update, the database is updated with the new item I entered,and it is stored within the database, but when I access the table again, it displays the LAST set of data. The first time through is fine. If I click on the submit button and second time the data is fine.

I am mystified as to why it is not showing the modified data. I have tried flushing, clearing the cache. Do not know why. Help!

Here is some of the code:

global $wpdb;

$Table_Name = $wpdb->prefix.’member_subscriptions’;

$sql_query = $wpdb->prepare(“SELECT * FROM $Table_Name”, 1) ;

$rows = $wpdb->get_results($sql_query, ARRAY_A);

if (!empty($rows))
{
foreach ($rows as $data)
{
$mmd_pms_not_logged_in_URL = $data[‘notloggedin_url’] ;
}


Not Logged In”/>

<input type="submit" value="Update" class="button-primary"/>

prepare(“UPDATE $Table_Name SET notloggedin_url=%s WHERE id=1”, $mmd_pms_not_logged_in_URL) ;
$wpdb->query( $sql_query );
}
?>

Read more here: data retrieval presents last set of data


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: