Good Morning,

This may be a simple yes or no, or hopefully if it is a no, someone can tell me how to work around it.

I have a table that includes 4 columns named the same with incremented numbers in the names

step1 / step2 / step3 / step4

I have a function in an obscure/remote place that I can't see the results of while it is being run, but don't seem to be getting the update that I expect from it.

I'm wondering if the structure of the update query is causing the problem or if I need to look somewhere else.

I'm trying to set the 'name' of the field to be updated through using a variable assigned in a switch case scenario.

        // #################################################
        //  UPDATE earned date for step1 - step4 in rewards prime

        switch($prime_reward_step){
          case 1:
            $step_value = 'step1';
            break;
          case 2:
            $step_value = 'step2';
            break;
          case 3:
            $step_value = 'step3';
            break;
          default:
            $step_value = 'step4';
            break;
        }

        $sql_u = "
          UPDATE rewards_prime
          SET ".$step_value."='".$created."'
          WHERE pid='".$prime_reward_pid."'
        ";
        mysql_query($sql_u);
        // #################################################

everything up before this point works, and the values assigned and updated, but not this one.

I'd like to know if using the $step_value as the column name is an acceptable format, and if not what would be a reasonable way to work around it.

thanks
Douglas

Member Avatar for iamthwee

$created is a variable yet I don't see it in your code?

Check for errors:

mysql_query($sql_u) or die(mysql_error());

Thank you both for responding...

iamthwee - the $created variable is passed into the function and is used in other queries that are functioning correctly, so it wouldn't be the issue, but it is set like this

$created = date("Y-m-d H:i:s", time()) ;

pritaeas - The problem with this is that the function is actually in a behind the scenes script that is called by a payment processor as the notification script on a successful payment, so even if I added the die to the query, I wouldn't see the results.

OK, I figured it out...

It wasn't that the query wasn't working, it was that the $prime_reward_step variable didn't have any value so it didn't know what to do.

Sorry to have bothered you with this...

Douglas

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.