There is nothing that prevent duplicates here.
When you create the table 'church'
is a good idea set a UNIQUE
sql index for field email, in this way you can rely on email address to preventing duplicate entries.
As a generic PHP good practice, you should check the existence of a a variable before using it, using isset
function:
/* If $_POST['email'] is setted and it is a valid email address */
if ( isset($_POST['email']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
global $wpdb;
$exists = $wpdb->get_var( $wpdb->prepare(
"SELECT COUNT(*) FROM 'church' WHERE email = %s", $_POST['email']
) );
if ( ! $exists ) {
/* Your insert code here */
}
}
P.S. Is also a good idea prepend the WordPress table prefix in front of custom table names.
Related Posts:
- Using wpdb to connect to a separate database
- WPDB Insert or if exists Update
- get_results using wpdb
- $wpdb won’t insert NULL into table column
- Detecting errors generated by $wpdb->get_results()
- wpdb update add current timestamp not working
- How to fetch Data in WordPress using MySQLi or $wpdb
- wpdb->insert multiple record at once
- How to define composite keys with dbDelta()
- Does wpdb add considerable overhead on queries with large result sets?
- Hook into $wpdb
- Display data from a non wordpress database on a page template
- How does $wpdb handle COUNT(*)
- How might I retrieve a featured post image from an external WP site and display it as a link back?
- WordPress database error: [Query was empty] [closed]
- Export wordpress table to excel
- How to close wpdb connection? [duplicate]
- Connecting to external oracle database
- Updating all rows of table with $wpdb
- Safe way to find last inserted id in a table?
- How to execute mulitple statement SQL queries using $wpdb->query?
- Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin
- Is $wpdb->prepare escaping to much? How to use it properly?
- Database slowdown after update to 3.4.1
- When and why should I use $wpdb different return types?
- How wordpress accesses its own database
- Remove database entries where post_date > expiration date
- Error connecting to DB in /wp-includes/wp-db.php on line 1538 [closed]
- How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?
- How to use a different database to list and manage comments in the backend
- Multiple postmeta with same name for one post in wp_postmeta table
- Cannot update custom database table row
- wpdb_prepare with multiple or condition
- Show last modified date of database
- $wpdb->insert is not working
- Extracting the post_id via the wp_insert_post action (external db query)
- WordPress database error – Error in SQL syntax – I can’t identify any error?
- In what part of the WordPress core does the users table and usermeta table get joined?
- Modify Database in Multi-Site wp_usermeta table
- Multiple wp_options tables to share content across installs
- $wpdb doesn’t like to store arrays
- Select two sums with single get_var statement
- Merging two wp_posts tables while avoiding duplicates
- Create table from array with prepare
- Update from 4.5 to 4.6 failing
- How Can I Put Meta_Compare in the Database-Query?
- WordPress running SQL query to update database from form
- How to fix database error duplicate entry
- I’m not able to get access to $wpdb [duplicate]
- WPDB SQL query with prepare() returning variable, not db value
- Have working sql query… trying to adjust it to use $wpdb
- $wpdb->query can’t insert data
- Custom WordPress Table wpdb
- How to fetch records from database WordPress
- Best practice to limit results in get_row()?
- Best practice to import user base (subscribers) from one website to another?
- AJAX wp-mysql running too slow
- CreateOrUpdate in WordPress
- Problem migrating to localhost
- Trouble running $wpdb->query() with last_insert_id
- How to get a list of WordPress default database tables?
- Connecting to a different database
- Using $wpdb | checking entered email against existing emails in db
- Query Column of Specific ID from Database Table
- How to delete a particular row in a database table
- How to create more than one new wpdb object?
- Optimizing function that automatically creates internal links based on post title string
- Update multiple rows in one query
- Get results from wordpress data custom table
- Should I use an additional column in the DB?
- Outputting query results
- access JSON results from wordpress database with wpdb
- Getting value from database table depending on field value
- Creating and Using Tables in the WordPress Database
- wpdb->insert not inserting first variable
- How do I have a user upload a blog post and then retrieve that to display in a card on the site?
- How to escape percentage sign(%) in sql query with $wpdb->prepare?
- How do I get database rows from a custom table using wpdb?
- SELECT rows between two datetimes when the range is dynamic [closed]
- How to insert a value to decimal type field using wpdb->prepare?
- Where is the HTML-handler part in the wpdb class?
- Help posting values to DB on submit using $wpdb->query
- How to add download link from database on custom page template?
- 2 $wpdb queries causing error Table ‘wp_postmeta’ is specified twice, both as a target for ‘UPDATE’
- insert data from a form:: Warning Empty query mysqli::query()
- How can I get $wpdb to show MySQL warnings?
- Correct and secure way to access a custom SQL database in a custom PHP template file
- About wp database hooks (error establishing connection)
- How to get specific table by current user login
- Accessing content from third party as native posts in WordPress
- Should I Use only wpdb Class to Write Custom Queries?
- Checking if the data already exsis in the wp database – custom plugin
- using same mysql user with many databases
- How can I retrieve data from alternate database using wpdb class?
- Pulling values from a sepcific row in table
- Inserting into data into external DB using WPDB
- Insert Extra fields added in the front end registration form to DB
- $wpdb->insert not working for last select option
- How to delete field using WPDB?
- Uploading to WordPress Database