Page 1 of 1
number plus number then show result
Posted: Sat Dec 30, 2006 10:32 pm
by eeau1973
hi ....
i would like to know how to ask to the user for two numbers ( maybe using a form )and then process those data to show the result (submitting those data)
thanks in advance

Posted: Sat Dec 30, 2006 11:01 pm
by richmix
Erm... might I ask why you want to do this?
re:why i must do this ...
Posted: Sat Dec 30, 2006 11:12 pm
by eeau1973
thats because i wanna know how the User input data and then how is it collected via the form and processed by the script
thaks again ,,,
Posted: Sat Dec 30, 2006 11:19 pm
by feyd
Basic math.

Posted: Sat Dec 30, 2006 11:20 pm
by neel_basu
HTML sender Page
==============
Code: Select all
.............................................
<form method = "get" action = "rcv.php">
<input type="textbox" name="n1" />
<input type="textbox" name="n2" />
</form>
...............................................
Reaciever php Script ( rcv.php )
======================
Code: Select all
<?php
echo "n1 : ".$_GET[n1];
echo "n2 : ".$_GET[n2];
?>
Posted: Sat Dec 30, 2006 11:21 pm
by feyd
neel_basu, you're missing quotes around the named elements of $_GET.
Posted: Sat Dec 30, 2006 11:28 pm
by neel_basu
although Its Good To Use Quoutes
But It would Work With / without qoutes
Posted: Sat Dec 30, 2006 11:30 pm
by richmix
The basic form structure in HTML looks something like this:
Code: Select all
<form action="action.php" method="post">
<input type="hidden" name="inputHidden" value="This input is hidden.">
<input type="text" name="inputText">
<input type="checkbox" name="inputCheckbox">
<input type="submit" value="Submit">
</form>
Breakdown:
Code: Select all
<form action="action.php" method="post">
This bit makes sure the form sends all of its variables to the file action.php. Setting the method to post is necessary because you're using this form to SEND information rather than retrieve it.
Here you define your input types. Each input type should have a unique name.
Now you need to set up your action.php file.
Code: Select all
<?php
/* This line extracts the POST variables; without it, your form variables will be part of the
$_POST array and look like $_POST['inputHidden'], $_POST['inputText'], etc. With this line,
your variables will look more presentable, such as $inputHidden, $inputText, etc. */
extract($_POST);
/* This line will echo "This input is hidden." */
echo $inputHidden;
/* This line will echo whatever is submitted from the text field. */
echo $inputText;
/* This chunk will echo "Yes" if the checkbox is checked and "No" if not. */
if ($inputCheckbox) {
echo "Yes";
exit;
} else {
echo "No";
exit;
}
Posted: Sat Dec 30, 2006 11:31 pm
by feyd
If you want your code to run without
any errors firing, it's required. Even if you don't mind E_NOTICE errors firing, they still happen if you turn them off, thus slowing your application down.
edit: it should be noted that extract() can lead to security compromises if not treated carefully. We will generally suggest using isset() or array_key_exists() against $_POST instead.