Here is my code
if (isset($_GET['ref'])) {
$ref_id= intval($_GET['ref']); // Sanitize input
// Query to get the project info
$projects = $wpdb->get_results($wpdb->prepare("SELECT * FROM table WHERE project_ref = %d", $ref_id));
‘ref’ is passed from previous page
However, the results are from the first line of table – even if I hard code the $ref_id.
Here is code from previous page.
.<a href="../projects?ref=<?php echo $ref; ?>"/><?php echo $_SESSION['project_name'];?>
Each link shows the correct $ref_id
Crazy. I have used similar coding on another page and it works but cannot see why this isn’t.
Hope you can help
2
Answers
Thanks everyone for their assistance. I changed the WHERE query to project id and all is good now.
I reformatted a few things for you and made some adjustments, I’ve commented my changes, haven’t tested this because I don’t have access to your DB.
Also, make sure you’re supposed to use
$_GET
instead of$_POST
for this? If the REF from the URL parameter is wrong, try$_POST
instead.