Inserting choice in database table


So I have this code:


global $wpdb;
// this adds the prefix which is set by the user upon instillation of wordpress
$table_name = $wpdb->prefix . "dbname";
// this will get the data from your table
$retrieve_data = $wpdb->get_results( "SELECT name FROM dbname" );
<form action="#" enctype="multipart/form-data" method="post">
<?php foreach ($retrieve_data as $retrieved_data) { ?>
     <th>Programma:</th><td style="vertical-align: middle;"><?php echo $retrieved_data->name;?></td>
     <th><input name="submit" type="submit" value="Abonneer" /></th>
//This is already able to update the name to "Jimbo". However, it needs to update the choice in the database
if(isset($_POST["submit"])) {

  global $current_user;

  $user_id = get_current_user_id(); //get the user id

  update_user_meta( $user_id, 'meta_value', 'Jimbo' );


With this code, I want to allow users to select a choice. Once they have made their choice, it will be saved in the database.

In my previous code, I updated the choices in the user table. I decided that it is in my advantage to save it in the wpex_usermeta table. However, the problem is that I do not know how I can update the choice in the database. For now I am just using the word ‘Jimbo’. The choices are saved in the variable $retrieved_data. But that contains all choices.

How can I make sure that when a user chooses something, his/her choice is updated in the database. The updating is already done. I just need to know how the choices are updated.

As you can see the word Jimbo in the meta_value (of user id 3) table is updated to Jimbo:

enter image description here

How can I make sure the choices are updated in the meta_value table?

, Johan Delft 4 years 2020-03-26T08:50:54-05:00 0 Answers 79 views 0

Leave an answer