Thread: php calculator
View Single Post
Old 06-19-2012, 09:09 PM   PM User | #4
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
Sure, well, first things first:

You have 2 forms, which do not work together. Think of a form as an envelope. In your first envelope, you have 4 radio buttons, which having the same name, will submit 1 piece of data. Your second envelope has 5 inputs and a submit. The 5 inputs have the same name, so they'll also only submit 1 piece of data. Submitting a form is like of like having one stamp... you have two envelopes with different data and one stamp... either you'll send your radio buttons data or your input (see right below here for why your input setup is wrong).

So the first lesson: names must be unique to submit uniquely. If you think about it, how does the system know which "number" to submit? Remember that variables must be unique in the same scope. So you first want to change the names to different things. The exception to that is radio buttons. Because radio buttons are about choosing one item out of a set, you give them the same name. Next, you need to review HTML specs for inputs. There is no "number" type, so your HTML instantly fails and won't work properly. Following specs is very important, as some browsers might be smart and figure it out, while others *cough*IE*cough* are sometimes very finicky.

After that, you should understand how forms submit. Once the data goes through successfully, the data submits via the method you specify. You put post, and PHP accesses post variables through the $_POST superglobal. So you would access your radio button through $_POST['calculator']. You can always print_r($_POST); to see what the post contains (it'll give you an idea as you experiment).

Next, I recommend googling something like "php form tutorial" or variations thereof. You'll find plenty with great basics. I would only recommend shying away from W3Schools tutorials/guides... they're great for basic info, but have a tendency to give wrong information.
Keleth is offline   Reply With Quote