View Full Version : Need Some Help !!!!
blueonline
May 6th, 2007, 14:19
I dont know php :confused4
i need a code that when entered a number in a text box will multiply and divide and add & substract with predefined numbers and will echo the result in another text box.
For eg
if user has entered 235644
then the script will multiply it 1256 then divide it with 23 and add 12354 and substract 12453 and show the result in another text box
i hope i have explained it :)
krakjoe
May 6th, 2007, 15:11
Your explanation isn't great, gimme a representation of the formula you wish to use, ie answer = ( posted x 2 ) / 3 + 15
Keagle
May 6th, 2007, 16:49
answer = (posted * 1256) / 23 + (12354 - 12453) or something along those lines. I think. :)
Here's one way:
<form action="/test.php" method="post" name="test"><input name="number" type="text" />
<input name="" type="submit" /></form>
<?
$userinput = $_POST["number"];
$multiplier = '1256';
$divider = '23';
$add = '12354';
$subtract = '12543';
$result = ((($userinput * $multiplier)/$divider)+$add)-$subtract;
if (!$_POST)
echo "No input number detected";
else
echo $result;
?>
Change the various multipliers/add/subtract values as needed by changing the variables in the top. You should probably also sanitize the user input before allowing it to be posted. ;)
blueonline
May 7th, 2007, 01:14
yea its like
the given text * 2568723232 + 134567 / 4564 - 1234 * 45677
like this..and if possible also sanitizing the text as mentioned by bear so they only post pure numbers
krakjoe
May 7th, 2007, 04:57
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="">
<script language="javascript">
// round to three decimal places, 10000 for 4 decimal places, etc
var precision = 1000 ;
function calculate( input )
{
if( parseInt( input ) != input )
{
return alert('Numnbers only please');
}
else
{
document.calc.result.value = Math.round( ( parseInt(input) * 2568723232 + 134567 / 4564 - 1234 * 45677 ) * parseInt( precision ) ) / parseInt( precision ) ;
}
}
</script>
<title>Untitled 2</title>
</head>
<body>
<form action="" name="calc" >
Enter a number : <input type="text" name="input" /><br />
Result : <input type="text" name="result" /><br />
<input type="button" value="Calculate" onclick="calculate( document.calc.input.value )" />
</form>
</body>
</html>
Your formula still doesn't look right .....
Keagle
May 7th, 2007, 06:17
There should be some brackets in there methinks?
You need to be careful about the math precedence. Some operations are done first, and in a particular order. Unless bracketed, operands like multiplication and division will be done first, possibly changing your result. Operations within parentheses are done before "loose" ones.
The one I offered gives the same result as a calculator. ;)
krakjoe
May 7th, 2007, 08:25
I really dont need tips on how to program, I have no idea what this guy is trying to achieve, thats why I asked him for a formula, I just took the forumla he gave and put it inside a script, I have no idea what any of these numbers are for and so I have no idea what order to do the math in, that's why I said the formula still doesn't look right, because it doesnt ......
If you're referring to my post, it wasn't directed at you but more of a general tip. I wouldn't presume to say you needed my help. ;)
blueonline
May 8th, 2007, 00:09
ok hear it wot this thing is all about... i have created a program in VB and i need to provide key online...
my program will generate randomly a 8 digit code .. which when entered here will generate another code which needs to be entered into the program in order to run
krakjoe
May 8th, 2007, 10:42
so you have written this in vb already??
paste the code you have written for vb, change the numbers but not the formula, you need the vb program and the website to generate the same code, so work it out in vb and I'll translate it to php, you shouldn't use javascript for this but I ddint know what you were doing, php definately ......
Kishadotcom
May 8th, 2007, 12:42
Here's the formula
(firsttextbox * 123456)/23 + 12354 - 12453 = result(in 2nd textbox) wherein the numbers 123456, 23, 12354 and 12453 are predefined
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.