Skip to main content
Known Participant
July 9, 2009
Question

UPDATE problems with PHP

  • July 9, 2009
  • 5 replies
  • 992 views

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!

This topic is closed to new replies. Start a new post to keep the conversation going.

5 replies

DwFAQ
Participating Frequently
July 10, 2009

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.

July 10, 2009

Actually, what's the value for  $colname_Recordset1 and  $colname2_Recordset1?

David_Powers
Inspiring
July 9, 2009

Please do not post duplicate threads. Your duplicate thread in the Dreamweaver forum has been deleted.

Known Participant
July 9, 2009

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.

David_Powers
Inspiring
July 9, 2009

Presumably, the second variable is a string, so it should be in (single) quotes.