PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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):
$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.
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.
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.