Copy link to clipboard
Copied
I'm trying to get certain page hit fields in my MySQL table to update if the criteria for two fields are met: campaign_ID = a URL variable and agent_email = another URL variable. Here's the code:
<?php
$result = mysql_query("SELECT * FROM RequestDB");
mysql_query("UPDATE RequestDB SET hits = hits+1 WHERE campaign_ID = $colname_Recordset1 AND agent_email = $colname2_Recordset1");
?>
My code works fine when the bolded/underlined/italicized part of the above code is removed from the code so that it reads:
<?php
$result = mysql_query("SELECT * FROM RequestDB");
mysql_query("UPDATE RequestDB SET hits = hits+1 WHERE campaign_ID = $colname_Recordset1");
?>
But it only updates fields that correspond to the first URL variable. How do I make it so that they correspond to both URL variables? Why isn't the code I'
ve proposed above working?
Thanks!
Copy link to clipboard
Copied
Presumably, the second variable is a string, so it should be in (single) quotes.
Copy link to clipboard
Copied
Please do not post duplicate threads. Your duplicate thread in the Dreamweaver forum has been deleted.
Copy link to clipboard
Copied
Sorry about the thread duplicates. I actually don't intend for the second variable to be a string; I want it to be exactly like the first one so that whatever URL variable I include in the URL acts as a further "filter" of what to modify on the database. I.e. $colname_Recordset1 defines a category, and $colname2_Recordset1 would define a subcategory.
Copy link to clipboard
Copied
Actually, what's the value for $colname_Recordset1 and $colname2_Recordset1?
Copy link to clipboard
Copied
You need to create a variable for colname2_Recordset1 so that it's = to the URL parameter agent_email.
Do this by adding something like this to your code above the query:
//create a variable for URL parameter
$colname2_Recordset1 = $_GET['agent_email'];
So your query should look something like this:
<?php
//create variable for URL parameter $colname2_Recordset1 = $_GET['agent_email'];
$result = mysql_query("SELECT * FROM RequestDB");
mysql_query("UPDATE RequestDB SET hits = hits+1 WHERE campaign_ID = $colname_Recordset1 AND agent_email = $colname2_Recordset1");
?>
Using this method you can create a variable for the first filter as well vs. using a recordset. This is just a basic concept of course. You may need to add conditions if there is no URL parameter passed.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now