I have a ref query string which matches rows in my wp_invites table.
In my wp_invites table, I have the following columns:
lead_namereference
Let's assume here is one of the rows:
Lead name: FreddyReference: 4FxtfVFszCHd
When the user accesses their invite, their URL will be something like: test.test/?ref=4FxtfVFszCHd
I am then getting this ref from the URL and trying to extract from the table row, if it exists. To do so, I have the following:
<?php
function get_reference(){
$get_reference = $_GET['ref'];
$get_reference = strval($get_reference);
return $get_reference;
}
global $wpdb;
$get_reference = get_reference();
$result = $wpdb->get_results( "SELECT * FROM 'wp_invites' WHERE 'reference' = '{$get_reference}' " );
foreach ($result as $post){
$lead_name = $post->lead_name;
echo '<p>'. $lead_name . '</p>';
}
?>
However, this yields a [You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''wp_invites' WHERE 'reference' = '4FxtfVFszCHd'' at line 1] error.
I had a feeling it may have been to do with a the get_reference() function call I was doing inside the query string. So I then changed it into a PHP var, but still seeing the same issue?