zaniac Posted April 28, 2008 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 Link to comment Share on other sites More sharing options...
justsomeguy Posted April 28, 2008 Share Posted April 28, 2008 $ans = arith($int1, $int2, $c);You didn't save the return value. Or..echo arith($int1, $int2, $c); Link to comment Share on other sites More sharing options...
zaniac Posted April 29, 2008 Author 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.