PHP multiplication and result show

Hello all,

I´m not sure if i´m on the right place to post this, i´m sorry if not.

I need some help with a php script i´m not good with php but can make few samll things.

What i´m looking for is a calculator " form " that has a fixed value when someone insert a value it should multiply that value over a fixed value.
My main problem is that the fixed value can chnage some times, so i need a option to change that value from a “admin” secction where i can protect that page with a password.

An example how it should work is: 25 * “fixed value 235” = 5.875
Someone entred the value 25 and it should show the result over the fixed (hiden) value.

Sorry for my bad English, thank you all.

<? if(!empty($_POST['one'])){ $a=$_POST['one']*235; echo"$a"; } ?>

Very nice simple and clear, but still need to 2 more options.

1- Is it possible to set 2-3 dif. values for $a=$_POST[‘one’]*235; ?
2- Can you help me to set up a page where i can change the predefined values wihtout the need to change it in the code ?

Thank you very much for ur help realy apreciat it.

yea I reread the post and realized I didn’t pay attention to where the value needed to be able to be changed
Since this is not a high security thing there wasn’t much need for database and mysql and md5 and all that yada yada yada :smiley: so I wrote a simple one here:
[php]<?php
$file=“value.txt”;

$handle = fopen($file, “r”);
$contents = fread($handle, filesize($file));
fclose($handle);
$static_number=$contents;

$password=“noneedforadmin”;
$string="{$_POST[‘one’]}";

if(strstr($string,$password)){

$pattern = ‘$password’;
$replacement = ‘’;

$newval= str_replace($pattern, $replacement, $string);

$fp = fopen($file, ‘w’);
fwrite($fp, $newval);
fclose($fp);
echo"Updated successfully!";

}

if(!empty($_POST[‘one’])){
$a=$_POST[‘one’]*$static_number;
echo"$a";
}
?>

[/php] so it works real simple it has a password to change the value, first create a txt file called value.txt adn put that in the same directory as this script, if you open value.txt just put 235 on the top line and close it, now it will automatically times everything by 235, if you want to change the value 235 to something else just enter the number that you want into the calculator followed by "noneedforadmin" which is the password then hit enter and the the value changed! example if I enter "100noneedforadmin" the calculator will now times everything by 100! hope that works for you! you can change the password to whatever you want, all you need is the two files, this one and value.txt

actually the other one did not work right :smiley: this one is better:
[php]<?php
$file=“value.txt”;

$handle = fopen($file, “r”);
$contents = fread($handle, filesize($file));
fclose($handle);
$static_number=$contents;

$string="{$_POST[‘one’]}";

if(strstr($string,‘noneedforadmin’)){

$pattern = ‘/noneedforadmin/’;
$replacement = ‘’;

$newval= preg_replace($pattern, $replacement, $string);

$fp = fopen($file, ‘w’);
fwrite($fp, $newval);
fclose($fp);
echo"Updated successfully!";

}

if(!empty($_POST[‘one’])){
$a=$_POST[‘one’]*$static_number;
echo"$a";
}
?>

[/php]

Just perfect …

JUst one thing i´m not sure if its possible.

Is it possible to show up 3-4 dif results? I mean, i need to have 3-4 dif. values example: 235 - 187 - 175

A big thank you from Portugal :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service