Jump to content

Displaying $_GET integers values


Recommended Posts

Hi,Have been trying to send a variable using a form, through the $_GET method. The variable is passed through, but does not display. Below is a copy of the code...

<html><head><title>forms</title></head><body><?php $int1 = $_GET['int1']; $int2 = $_GET['int2']; $c = $_GET['calc']; if(isset($_GET['submitted'])){ function arith($int1, $int2, $c) { if ($c == 1) { $ans = $int1 + $int2; } elseif($c == 2) { $ans = $int1 - $int2; } else{ $c == 3; $ans = $int1 * $int2; } return $ans; }arith($int1, $int2, $c);echo $ans ;} $calc = array( 1=> '+', 2=> '-', 3=> 'x' );?><form method="get" action="get_post.php" ><input type="text" name="int1" size="25" /> <?php echo'<select name="calc" >';foreach($calc as $key => $value){ echo '<option value="'. $key . '">' . $value . '</option>'; }echo'</select>';?><input type="text" name="int2" size="25" value="" /> <input type="submit" name="submitted" value="send" /></form></body></html>
Am I missing a function here? Any help, is very much appreciated :)
Link to post
Share on other sites
$ans = arith($int1, $int2, $c);You didn't save the return value. Or..echo arith($int1, $int2, $c);
A big thank you amigo :) I cannot understand why I cannot do the small things in PHP. The other day I wasted half a day trying to figue out why the page would not display after hitting the submit button. I eventually realised my Apache server was offline :)
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...