Hey, I thought that it would be good if I got some help here. Please tell me if you know a way by which I can create a script that allows users to enter any number in a textbox and when they click on a button, that number's square should appear. Help would be appreciated....
PHP Math
| Code: |
| <?php
if (isset($_POST['number'])) { $number = intval($_POST['number']); echo sqrt($number); } else { ?> Type in the number to be square rooted<br /> <input type="text" name="number" /> <input type="submit" /> <?php } ?> |
Name it a .php file. (something.php)
If it doesn't work, tell me, I just coded this in the broswer and didn't test it P
Hey thanks for being so helpful 0obie, I'm giving you 30 more FRIH$. Let me try the script. I'll definitely tell you if it works.......
Hey, it doesn't work!!!
My bad, use this code below. I forgot the <form> tags.
http://bondings-world.frihost.net/page.php (try it)
| Code: |
| <?php
if (isset($_POST['number'])) { $number = intval($_POST['number']); echo sqrt($number); } else { ?> Type in the number to be square rooted<br /> <form action="page.php" method="POST"> <input type="text" name="number" /> <input type="submit" /> </form> <?php } ?> |
http://bondings-world.frihost.net/page.php (try it)
Do you really need a transaction to get a number's square? You might like JavaScript better:
Or, if you insist, here is a short PHP script that does the job:
Use .html extension with the first one, and .php with the second.
I hope it helped.
| Code: |
| <html>
<head> <title>Square.</title> <script language="javascript"> function square() { if (!isNaN(nu.value)) sq.value=nu.value*nu.value else { window.alert("Numbers only."); nu.value=""; } } </script> </head> <body onload="javascript:nu.focus();"> <input type="text" id="nu" /> <input type="text" id="sq" /> <input type="button" value="Square" onclick="javascript:square()" /> </body> </html> |
Or, if you insist, here is a short PHP script that does the job:
| Code: |
| <html>
<head> <title>Square.</title> </head> <body onload="javascript:nu.focus();"> <form> <input type="text" name="nu" id="nu" /> <input type="submit" value="Square" action="<?php $_SERVER['PHP_SELF']; ?>" method="get" /> </form> <?php if (isset($_GET['nu'])) echo($_GET['nu']*$_GET['nu']); ?> </body> </html> |
Use .html extension with the first one, and .php with the second.
I hope it helped.
Hey 0obie, could you create a similar page which has two text-boxes where one can enter two numbers that shall be added, multiplied & divided? Could you also put the source code here, along with a link to it? PLEASE DO THAT FOR ME - COME ON....I GAVE YOU 50+ FRIH$!!!!!
please

| assex wrote: |
| Hey 0obie, could you create a similar page which has two text-boxes where one can enter two numbers that shall be added, multiplied & divided? Could you also put the source code here, along with a link to it? PLEASE DO THAT FOR ME - COME ON....I GAVE YOU 50+ FRIH$!!!!!
|
Why don't you do it yourself? The nice thing about programming is the control that you have over the computer... the only thing is that you'll have to learn it, but it isn't hard at all. You'll also don't have to wait for someone to post source-code, you just could do it yourself. Isn't that great? (yes it is!)
| assex wrote: |
| Hey 0obie, could you create a similar page which has two text-boxes where one can enter two numbers that shall be added, multiplied & divided? Could you also put the source code here, along with a link to it? PLEASE DO THAT FOR ME - COME ON....I GAVE YOU 50+ FRIH$!!!!!
|
Sure, just give me a few hours or so, I'm kinda busy now. I'll post the source code & demo page in a few hours.
(and I'm sure it wasn't 50+FRIH$, I just saw lots of decimal places
| Code: |
| <?php
if (isset($_POST['mode'])) { $number1 = intval($_POST['number1']); $number2 = intval($_POST['number2']); $mode = $_POST['mode']; if ( $mode == "add" ) { echo $number1+$number2; } elseif ( $mode == "subtract" ) { echo $number1-$number2; } elseif ( $mode == "multiply" ) { echo $number1*$number2; } elseif ( $mode == "divide" ) { echo $number1/$number2; } else { echo "Error"; } } else { ?> Type in the numbers to be calcuated<br /> <form action="page.php" method="POST"> <input type="text" name="number1" /> <input type="text" name="number2" /><br /> <input type="radio" name="mode" value="add">Add</input> <input type="radio" name="mode" value="subtract">Subtract</input> <input type="radio" name="mode" value="multiply">Multiply</input> <input type="radio" name="mode" value="divide">Divide</input> <input type="submit" /> </form> <?php } ?> |
http://bondings-world.frihost.net/page.php
Thanks a lot 0obie!!!!!!!! You are really helpful!!!!!
Trading FRIH$ for sqrt... This forum isn't a market place !
assex, you'd maybe better learn scripting yourself. If you really need this sqrt script that you can't do, then learning scripting will be very useful !
assex, you'd maybe better learn scripting yourself. If you really need this sqrt script that you can't do, then learning scripting will be very useful !
Well, its okay now, coz I have got the hang of using this sort of a script.....
I've understood the basics of PHP Math....
Now, I am developing a calculator that is very advanced......I'll post here again when it is ready......
I've understood the basics of PHP Math....
Now, I am developing a calculator that is very advanced......I'll post here again when it is ready......
Start a new topic by then
.
closing this.
-close-
closing this.
-close-
