zaniac 0 Posted April 28, 2008 Report Share Posted April 28, 2008 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 Quote Link to post Share on other sites
justsomeguy 1,135 Posted April 28, 2008 Report Share Posted April 28, 2008 $ans = arith($int1, $int2, $c);You didn't save the return value. Or..echo arith($int1, $int2, $c); Quote Link to post Share on other sites
zaniac 0 Posted April 29, 2008 Author Report Share Posted April 29, 2008 $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 Quote Link to post Share on other sites
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.