I am creating my first ever plugin for a membership site. I have a custom table named subscription with a subscr_user_id column whose values are taken from $current_user->ID. So when a current user subscribes, a new record is inserted into the table where subscr_user_id gets the value of the current user's ID. How do I query(INSERT AND SELECT) the table from a template(I don't know of any other means to test queries)?
I have this SELECT query: Note that I have preinserted one record into table subscription with subscr_user_id = 1 which means the user is an administrator. I did that thru sql console.
//Somewhere in between the body of the template. //This query will be used for a code that checks if a user ID is already subscribed to avoid duplicate records. global $current_user; global $wpdb; $user_id = $wpdb->get_row("SELECT * FROM $wpdb->subscription WHERE subscr_user_id = $current_user->ID"); echo '<p> Current user ID is:'.$user_id->subscr_user_id. '</p>'; Before I viewed the page that uses that template, I logged in as an administrator to make sure the ID is 1. Unfortunately I didn't get any result? Could anyone also please show me a sample of INSERT statement?