Hillary Posted March 10, 2008 Share Posted March 10, 2008 My assignment is to create a function that calculates the sum of two numbers. The function will have two parameters, one for each of the numbers to be added. After the total is computed, it should be returned and then displayed. *i already know how to pass multiple values to a function. *i already know how to add two values and store the answer in a variable. *i already know how to return a value from a function, but pretty much i can only return strings, thats all we've worked on at school. ----------------------------------------------------------------------------------------- this is the work i have done so far, i have included a few functions from my file functions.php. on the web it displays everything, it looks right with the text areas, plus, equals, when i click submit it goes to the action page... but i dont even know where to start with the action page. should i even use one? is there a way for me to get the answer to print on the same page? the goal i think is to have 2 blank text areas the user types in a value in to each and it will come up with the answer. <?php include "functions.php"; $f = form_open("sumof2answer.php"); print $f; $h = hidden(""); print $h; $t1 = text_area("val1", 1, 1); $t2 = text_area("val2", 1, 1); $a = sum($t1, $t2); print $a; $s = submit(); print $s; ?> -------------------------------------------------------------------------------------- it looks like this [___] + [___] = (submit) i dont know what to do. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted March 10, 2008 Share Posted March 10, 2008 in PHP, numbers are just like strings. just return the number from the function as you would a string. Quote Link to comment Share on other sites More sharing options...
frijole Posted March 10, 2008 Share Posted March 10, 2008 you will have to submit the numbers whatever you do. Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 10, 2008 Share Posted March 10, 2008 Check out your form_open() function in functions.php If it says <form method="POST"... use $_POST['val1'] and $_POST['val2'] to grab what the user entered into the text boxes in sumof2answer.php If it says <form method="GET"... use $_GET['val1'] and $_GET['val2'] to grab what the user entered into the text boxes in sumof2answer.php Alternately, you can use $_REQUEST['val1'] which grabs from either post or get... but I prefer to keep them separate. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.