I have a php script that listens for $_POST input, and inserts into my table which can then be read in my Wordpress plugin and displayed to the admin. Given how people submit forms multiple times, I check the database to see if the entry already exists, using a unique invoice number that is sent in the form.
My code is:
global $wpdb;
$submits_table = $wpdb->prefix . 'submits_table';
$invoice = $_POST['invoice'];
$exists = $wpdb->get_row( "SELECT * FROM $submits_table WHERE `invoice` = $invoice" );
if ( $exists == NULL ) {
$wpdb->insert(
$submits_table,
array(
'first_name' => $_POST['first_name'],
'ip_address' => $_POST['ipaddress'],
'invoice' => $invoice
),
array(
'%s',
'%s',
'%s'
)
);
}
The problem is that every single submission gets inserted, regardless whether the invoice number already exists or not. I've tried this same code on a different page from the Admin panel and it works okay; it's only when it's set as a listener for the front end submissions does it not work right.
I'm ripping my hair out. Any ideas as to why get_row()
is returning NULL every time on the front end but not the admin?
EDIT: invoice
is alphanumeric, so it's varchar
.