Jump to content

[SOLVED] setting a value


ngreenwood6

Recommended Posts

I have a script that puts a user inputted value into the database.  It can be put in as either a debit or a credit. If it is a credit it will be positive and if it is a debit it will be negative.  I have created a drop down box that allows them to select debit or credit. However I just want them to be able to select either debit or credit and if it is debit automatically put a "-" in front of the number. The reason is because later it is called and the values are added. If not the user will have to put a "-" when they enter the value. Does anyone know how I can do this?  I have something like this but it doesnt work:

 

if($type == "Debit")
{
$amount = "-$amount";
}

 

I have tried some others but none seem to work. Any help is appreciated.

Link to comment
https://forums.phpfreaks.com/topic/127921-solved-setting-a-value/
Share on other sites

I need to see more of your code to help but, try using this:

 

if($type == "Debit") {
$newamount=.'-'.$amount;
}

 

... And then insert $newamount into your database.

 

And where is your $amount variable originally being called? If the number is being input by a user, there should be a line of code somewhere that looks something like:

 

$amount= $_POST['amount'];

 

(That's assuming you've named your text input box "amount")

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.