Jump to content

Recommended Posts

I am attempting to pull a URL variable and drop it into a WHERE clause, however, I am having no luck!  The URL variable does seem to pass to the mySQL query, but the query fails.  From my research, it appears to be a syntax issue.

Here is what I have:

[code]$cid = $_GET['campaign'];
mysql_select_db($database_Offer, $Offer);
$query_Offer = "SELECT tos FROM offers WHERE campaign = `'$cid'`";
$Offer = mysql_query($query_Offer, $Offer) or die(mysql_error());
$row_Offer = mysql_fetch_assoc($Offer);
$totalRows_Offer = mysql_num_rows($Offer);[/code]

The error I get is as follows:

[quote]Unknown column ''10000'' in 'where clause'[/quote]

I have a text box that will be populated with the data being pulled form the above query in which I have the following code:
[quote]<?php echo $row_Index['tos']; ?>[/quote]

The table name is "offers" and the columns I am attempting to pull data from are "tos" and "campaign".  The URL for this page is http://www.allinonevacations.net/collect.php?campaign=10000.

Thanks.
Link to comment
https://forums.phpfreaks.com/topic/32054-solved-url-variable-in-where-clause/
Share on other sites

Why do you have tics AND single quotes around your variable? When you're referencing a value in SQL, just use the single quotes. Change that up and see what you get:
[code]
SELECT tos FROM offers WHERE campaign = '$cid'
[/code]
Good eyes.  I thought that, too, as per the mySQL manual.  However, for some reason, having both tics and quotes gets the URL variable to pull.  Having only single quotes does remove the error message, but the URL variable does not pull.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.