Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

UPDATE problems with PHP

New Here ,
Jul 08, 2009 Jul 08, 2009

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!

TOPICS
Server side applications
987
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 09, 2009 Jul 09, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 09, 2009 Jul 09, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 09, 2009 Jul 09, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 09, 2009 Jul 09, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jul 09, 2009 Jul 09, 2009
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines