shahg Posted April 16, 2013 Share Posted April 16, 2013 (edited) I have made a simple calculator but i am unable to print the result value in the form.please help.please check my coding. Html coding: <html> <head> <title>calculator</title> <link href="new.css" type="text/css" rel="stylesheet"/> </head> <body> <form action="new.php" method="POST" name="calculator"> <h1> calculator</h1> <p> <strong>Frsit value</strong> <input name="f_value" type="text" value="<?php $first_value ; ?>" maxlength="50"> <p><strong>Second value</strong> <input name="s_value" type="text" value="<?php $sec_value; ?>" maxlength="50"> <p> <input name="add" type="submit" value="add"> <!-- <input name="sub" type="submit" value="sub"> <input name="sub" type="submit" value="multiply"> <input name="sub" type="submit" value="divide">--> <p> <h2 style="border:thick">Result <input name="result" type="text" maxlength="50" value="<?php echo $result ; ?>" > </h2> </form> </body> </html> Css : form { display:block; background-color: #333399; width:300px; height:500px; border:thick; border: #330000; color: #FFCC00; } h1 { text-align:center; z-index: 2px; } php coding : <?php $first_value = $_POST['f_value']; $sec_value = $_POST['s_value']; $error = ""; //--calculation variables---// if(isset($_POST['add'])){ $result = $first_value + $sec_value; header("location: new.html"); } Please tell me how to get my value inside result field. Edited May 18, 2013 by ignace Added code tags Quote Link to comment Share on other sites More sharing options...
shahg Posted April 17, 2013 Author Share Posted April 17, 2013 (edited) <html> <head> <title>calculator</title> <link href="new.css" type="text/css" rel="stylesheet"/> <?php if(isset($_POST['add'])){ $first_value = $_POST['f_value']; $sec_value = $_POST['s_value']; //--calculation variables---// $result = $first_value + $sec_value; } ?> </head> <body> <form method="post" action="new.php" name="calculator"> <h1> calculator</h1> <p> <strong>Frsit value</strong> <input type="text" name="f_value" > <p><strong>Second value</strong> <input type="text" name="s_value" maxlength="50"> <p> <input name="add" type="submit" value="add" > <!-- <input name="sub" type="submit" value="sub"> <input name="sub" type="submit" value="multiply"> <input name="sub" type="submit" value="divide">--> <p> <h2 style="border:thick">Result <input type="text" maxlength="50" value="<?php echo $result ; ?>" Name='result' > </h2> </form> </body> </html> I have edit it but getting error that variable result is not defined Edited May 18, 2013 by ignace Added code tags Quote Link to comment Share on other sites More sharing options...
Barand Posted April 19, 2013 Share Posted April 19, 2013 Give your submit buttons the same name, say "sub". Check the value of $_POST['sub'] to see what you do with inputs Quote Link to comment Share on other sites More sharing options...
ignace Posted May 18, 2013 Share Posted May 18, 2013 (edited) When posting code please always use your code goes here tags. You can find them as on the editor. Edited May 18, 2013 by ignace 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.