Jump to content

assignment for class... math something? i don't know.


Hillary

Recommended Posts

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.

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.