There are several problems with your function. For example, $tablename
points to a table that does not exist. And you don’t need it anyway.
If you are trying to create a new user if that email does not exist then try this:
function register_user() {
global $wpdb;
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$checkIfExists = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE email="$email"");
if ($checkIfExists == NULL) {
$userdata = array(
'user_login' => $name,
'user_email' => $email,
'user_pass' => $password,
);
$user = wp_insert_user( $userdata );
}
}
Related Posts:
- Accessing two databases wordpress
- How can I connect to a second database and still be able to use wp functions like get_post_types()?
- Writing a function for WP Cron to run a SQL command daily
- Most efficient way to get custom database records from 20 buttons and 20 tables?
- How to update BuddyPress xprofile fields programmatically? [closed]
- Best Practice for Syncing Local Development With Staging Development [closed]
- Is it good practice to use wpdb->query() function?
- Remove the deleted users avatar from list
- when I fetch data from remote mysql database in wordpress built in wordpress function is not working?
- WordPress shortcode attributes for database SELECT?
- Trying to establish connection to External Database
- How to insert a single row to WP database table?
- Which action does wp_update_user triggers?
- Wp_query function to search from product_title ‘OR’ product tags name
- Updating Media Published Date When Parent Post Is Modified in WordPress
- Is there a WP function to get taxonomy name from taxonomy_term_id?
- Get User Login Data (date, time… )
- Multisite 404 on pages – rewrite error breaks database
- Connecting to a 2nd DB gives me no results when querying
- Is There Any Built In WP Functionality For Combining Form Fields To Return Specific Data
- Check if a value exists in database table
- wp_usermeta – Read from database, but save function broken
- Get the alphabetical sorted data with wpdb
- How to loop while adding data to database?
- Update wp_postmeta table based on 2 keys
- sort title descending with title with number
- Delete oldest wordpress post (SQL query)
- Button click counter for login user
- Function stops working
- What to do to have access to WordPress functions
- Database SQL Error, Should Work
- Database Query not working
- Function returning queried meta value based on current post ID
- How to add next height number in Order Attributes inside the Add new page. [duplicate]
- Function to get the name in database table from the comma separated string
- Functions file mods and CPU
- Bulk set Post Title as Tag where Tag is Empty Function
- WPDB query suddenly not working
- Ajax call always returns 0
- How to override a function when isn’t at functions.php
- contactform7 remove tags with “wpcf7_autop false” from functions.php
- How to count number of functions attached to an action hook?
- Show modified time if post is actually modified
- ajax live search for post title
- Hourly Routine Not Firing ( wp_schedule_event() )
- How to get an array of menu items from the toolbar?
- Fatal error: Call to undefined function add_action() – an untouched problem
- echo or print_r in an admin function
- Automatically Add Specified Value to Attachment Metadata upon Upload
- Bootstrapping WordPress MultiSite Outsite of WordPress – No $wpdb
- img width and height attributes being set by get_the_post_thumbnail
- echo get_post_meta()
- Extracting the post_id via the wp_insert_post action (external db query)
- Retrieve tags data in post body
- Remove H1 / title / Underscore – without CSS
- Custom Static Links For Specific Menu Right Before/Next The wp_nav_menu Function now working
- Current path on page in functions.php
- How do you publish a draft on WordPress
- How can I recompile js file in dist folder?
- Show Primary Category first when I display post categories
- Setting youtube size in functions.php
- Redirect to another page if the user is logged in when pressing again the login button on menu bar
- wp_get_archives custom function broken since upgrading to WP 3.7.1
- How to get correct value from checked()?
- While loop with an exception after a count is reached
- Return child theme url
- Redefine function arguments before rendering
- Enqueue script on every page except one
- Best way to handle lack of titles in microblogging
- Functions php shortcode for displaying main menu with no child items
- Problem migrating to localhost
- Redirect to other page if login
- first paragraph of the_content as meta description
- get_terms (or tax_query) for term of current post?
- Do we need to change our child function.php to require/include child dir files when we add an over-riding file.php into the child theme
- How to use get_posts() function in functions.php
- Redirect to post after publish or update a published post
- Page Template Won’t Load Correct CSS File
- How to display this meta data (an array) in form of a function (created with a custom write panel)?
- WordPress – using sessions?
- Use a filter for wp_robots to block CPT/feed/
- Trigger email alert if file downloaded
- Completely Disable WordPress RSS Feeds
- How to hide content on mobile in the functions.php file – woocommerce
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- Order column custom date using pre_get_posts
- query_vars treat as single var from URL
- Running javascript without hooking wp_head
- Remove text after a dot and a colon in Woocommerce product title
- Selecting specific query for offset
- Show image after X para – center aligned
- what is `get_section()` and how to use it?
- function replace_text for entire page
- Should I Use only wpdb Class to Write Custom Queries?
- Only Show One Category Name Per Post
- Pass max posts to Javascript
- update_usermeta don’t work
- WP supersize not displaying when different languages flags are selected
- wp_list_pages change of children and anchor of parent
- Comment turned Invisible