So, I will have a page where a user lands with a /?ref=123 type ending on the URL.
Then, what I want to achieve, is to use that ref 123 in a MySQL query, like this:
SELECT foo FROM table WHERE table.ref = 123
The issue I have hit is that if i use $_GET to get the variable, it breaks my SQL query (obviously!)
SELECT foo FROM table WHERE table.ref = $_GET['ref']; falls over because $_GET is not a MySQL function.
Trouble is, I want to dynamically create page content based on the ref value but I can't figure how.
Any help gratefully accepted.
Timezone GMT+13 so replies will potentially be slow :)
**********EDIT**********
As I may not have given enough info in the OP, here's the code I'm struggling with:
<?php
global $wpdb;
header('Content-Type: text/html; charset=utf-8');
include "../../../wp-config.php";
$get_donation_amount = "select SUM(amount) AS total_donations from SaveContactForm7_1 where ref = 123 ";
$get_donation_amount_result = $wpdb->get_results($get_donation_amount);
$total_donation = isset($get_donation_amount_result[0]->total_donations) && $get_donation_amount_result[0]->total_donations !="" ? $get_donation_amount_result[0]->total_donations :"0" ;
?>
What I need to do is add a call to the URL for the value of ref and add it where shown with the SQL querycode. Then a particular donor who knows his 'ref' value will see results relevant to him alone.
$_GET? How to concatenate a string to be used as a SQL statement executed as any other SQL statement in the existing database connection you have? Really? Although all such tutorials show exactly that? Sorry, but it looks as if you either are not really following any tutorials or you are simply not willing to understand what you are shown. Of course you can use a variable in an SQL query (whether you should is another question). What you yourself posted will work if done correctly (you do not show how you use it).