I'm having a strange problem with a website I'm working on. What I want to do is pass a SQL query variable (in this case cid) using a link, but for some reason it just isn't working.

This type of query works just fine on other pages of this site, but when I try it here, the variable isn't passed.

Here is my SQL query:

$query = 'SELECT CID AS "Course ID", courseNumber AS "Course Number", courseNumber AS "Course Number", startDate AS "Starts", endDate AS "Through", facAddress as "Location", facCity as "Location", county as "County" FROM class where CID="$cid"';

I would think that this link would then pass the CID number (in this case 12) to the report query.

https://www.contractor-training-ca.org/mailer/report.php?cid=12

Instead, I get this error:
Unknown column '$cid' in 'where clause'

It's probably something really stupid that I'm missing, any help would be appreciated...

Hi

you have to get the cid value

$cid = $_GET['cid'];

insert the above line before your code starts in the page.

Let we check.

Member Avatar for wangsg

$query = 'SELECT CID AS "Course ID", courseNumber AS "Course Number", courseNumber AS "Course Number", startDate AS "Starts", endDate AS "Through", facAddress as "Location", facCity as "Location", county as "County" FROM class where CID='.$cid;

Still having the same issue. Inserted the code as suggested but it didn't make any difference. Here is my page code:

<?php

$cid = $_GET['cid'];
include ('config.php');
include ('sqlreporter.php');

//Setup Email Subject
$subject = 'Welcome to the Subsidized Contractor Training Program';

//Color is the color report table, it can be set to be grey, green or blue
$color = 'gray';

$header = '<p><b>Welcome to the Subsidized Contractor Training Program</b>. 
</br></p>';

$footer = '<p><strong>Subsidized Contractor Training </strong> is brought to you by Energy Upgrade California and Conservation Services Group.</p>';

$query = 'SELECT CID AS "Course ID", courseNumber AS "Course Number", courseNumber AS "Course Number", startDate AS "Starts", endDate AS "Through", facAddress as "Location", facCity as "Location", county as "County" FROM class where CID="$cid"';

$report = generateReport($query, $header, $footer, $color);

$recipient1 = 'rdulay@gmail.com';

html_email($recipient1,$subject,$report);


?>

If I put any class id (CID) in the SQL query, it works just fine, but passing it through the URL is still failing.
https://www.contractor-training-ca.org/mailer/report.php?cid=12

Member Avatar for wangsg
CID="$cid"';   change    CID='.$cid;

Thank you!!

$query = 'SELECT CID AS "Course ID", courseNumber AS "Course Number", courseNumber AS "Course Number", startDate AS "Starts", endDate AS "Through", facAddress as "Location", facCity as "Location", county as "County" FROM class where CID='. $cid .'';

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.