Page 1 of 1

Need help with a return problem

Posted: Sat Aug 01, 2009 9:31 pm
by dogman8
I am entering PHP into an application that updates an mySQL database.

I have entered this code (which takes the weight of a product from a csv file and manipulates it the way I want and places it into the $products[weight] table and field of the mySQL database):

Code: Select all

$actual_value = $P[5];
if ($actual_value > 0) {
$temp1 = $actual_value + .25;
$temp2 = $temp1 * 2;
$temp3 = round($temp2, 0);
return($temp3 / 2);
} else {
*this is what I can't get to work*
}
If $actual_value does = 0, I want the current weight in the database to be preserved instead of a 0 being returned as is always the case, no matter what I try.

Any Help????

Re: Need help with a return problem

Posted: Sat Aug 01, 2009 11:13 pm
by requinix
Can't you make it return the original value? After all, setting something to be the same value it currently has is the same as not changing it - unless you have triggers on your tables.

If not then you have to make the code that calls this function (that code is part of a function, right?) decide whether to do the update or not.

Re: Need help with a return problem

Posted: Sat Aug 01, 2009 11:21 pm
by dogman8
Hence the problem. This is a snippit entered into an base64 encoded PHP application. The only control I have is what you see above. No matter what I try to return, even an unset variable, nothing stops this from updating the field to 0... well except die, that kills the whole script. I was just hoping I was missing some simple function or code that would prevent the update.

Re: Need help with a return problem

Posted: Sun Aug 02, 2009 12:12 am
by requinix
What's the code for the entire function? That might give a clue as to something you could do.

If you can see/read the code that uses this function, post that too.