dink87522 Posted November 14, 2008 Share Posted November 14, 2008 Can I please have ome help with my first php calculator. I have calculator.php <html> <head> <title>PHP Calculator</title> </head> <body> <h2>Calculator</h2> <?php // This is my first attempt at creating a simple PHP calculator ?> <form name="form1 method="post" action="process.php"> <label> <input name="answer" type="text" value="$answer"> <br /><br /> </label> <label> <input name="1" type="button" id="1" value="1"> <input name="2" type="button" id="2" value="2"> <input name="3" type="button" id="3" value="3"> <input name="+" type="button" id="10" value="+"> <br /> <input name="4" type="button" id="4" value="4"> <input name="5" type="button" id="5" value="5"> <input name="6" type="button" id="6" value="6"> <input name="-" type="button" id="11" value="-"> <br /> <input name="7" type="button" id="7" value="7"> <input name="8" type="button" id="8" value="8"> <input name="9" type="button" id="9" value="9"> <input name="x" type="button" id="13" value="x"> <br /> <input name="0" type="button" id="12" value="0"> <input name="/" type="button" id="14" value="/"> <input name="=" type="submit" id="15" value="="> </label> </form> </body> </html> and process.php <?php $one = $_POST['1']; $two = $_POST['2']; $three = $_POST['3']; $four = $_POST['4']; $five = $_POST['5']; $six = $_POST['6']; $seven = $_POST['7']; $eight = $_POST['8']; $nine = $_POST['9']; $zero = $_POST['0']; $add = $_POST['+']; $minus = $_POST['-']; $multiply = $_POST['x']; $divide = $_POST['/']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/132718-my-first-calculator/ Share on other sites More sharing options...
revraz Posted November 14, 2008 Share Posted November 14, 2008 Need to explain more on what kind of help you need, what the problem is, what errors you get..etc Quote Link to comment https://forums.phpfreaks.com/topic/132718-my-first-calculator/#findComment-690199 Share on other sites More sharing options...
dink87522 Posted November 14, 2008 Author Share Posted November 14, 2008 I'm stuck, I don't know where to go next. Quote Link to comment https://forums.phpfreaks.com/topic/132718-my-first-calculator/#findComment-690201 Share on other sites More sharing options...
PFMaBiSmAd Posted November 14, 2008 Share Posted November 14, 2008 Go where with what? Programming is a very detail oriented activity. When asking a question you need to be specific. So far you have posted a form and some php code that consists of some assignment statements. I would guess you are asking how to write the code that implements a calculator in the form processing code? Quote Link to comment https://forums.phpfreaks.com/topic/132718-my-first-calculator/#findComment-690208 Share on other sites More sharing options...
nitation Posted November 14, 2008 Share Posted November 14, 2008 When u run your code, do you get any error or what? Quote Link to comment https://forums.phpfreaks.com/topic/132718-my-first-calculator/#findComment-690224 Share on other sites More sharing options...
dink87522 Posted November 14, 2008 Author Share Posted November 14, 2008 No, no error. Quote Link to comment https://forums.phpfreaks.com/topic/132718-my-first-calculator/#findComment-690505 Share on other sites More sharing options...
Maq Posted November 15, 2008 Share Posted November 15, 2008 You need to compile and store what has been clicked on. Right now if you click submit, there's nothing to send... An easy way to do this is when a button is clicked store the values in a string delimited by a comma so now you can pass the whole string, explode it, and have case statements for your operators in process.php. You could actually do it all on the same page. Have a function that takes in a string and when submit isset call the function and return the calculation. Of course you're going to have to validate, but let's get it working first. Next time add some detail/research to your question. Something like: I am trying to create a basic calculator. I have buttons in calculator.php with all the digits and operators. I don't know how to store the values, when they are clicked, and send them to process.php so I can do the calculation. I do not get any errors. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/132718-my-first-calculator/#findComment-690512 Share on other sites More sharing options...
.josh Posted November 15, 2008 Share Posted November 15, 2008 We had a contest a while back that involved making a graphing calculator. Do a forum search. Quote Link to comment https://forums.phpfreaks.com/topic/132718-my-first-calculator/#findComment-690516 Share on other sites More sharing options...
dink87522 Posted November 15, 2008 Author Share Posted November 15, 2008 We had a contest a while back that involved making a graphing calculator. Do a forum search. I did. The only 'graphics calculator' post found was your post just above. Quote Link to comment https://forums.phpfreaks.com/topic/132718-my-first-calculator/#findComment-690744 Share on other sites More sharing options...
.josh Posted November 15, 2008 Share Posted November 15, 2008 hmm I guess one of the admin must have just deleted that forum. It's been inactive for a while... Quote Link to comment https://forums.phpfreaks.com/topic/132718-my-first-calculator/#findComment-690748 Share on other sites More sharing options...
Maq Posted November 15, 2008 Share Posted November 15, 2008 I found this for you, very basic... Quote Link to comment https://forums.phpfreaks.com/topic/132718-my-first-calculator/#findComment-690859 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.