Need help with coding for a forum that adds numbers
Discuss Need help with coding for a forum that adds numbers in the PHP Development forum on Dev Shed. Need help with coding for a forum that adds numbers PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
Posts: 7
Time spent in forums: 31 m 39 sec
Reputation Power: 0
Need help with coding for a forum that adds numbers
I need help with coding a page that has two fields so when you put a number in each one and press a button that says add, the output is the answer. almost like its a calculator
Posts: 294
Time spent in forums: 3 Days 8 h 5 m 6 sec
Reputation Power: 5
Sorry to toss a note in at the end here, but if you've some free time, you may be more interested in doing this via Javascript. This will avoid submitting the page every single time, and process it live on the client-side.
Posts: 7
Time spent in forums: 31 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by Triple_Nothing
Sorry to toss a note in at the end here, but if you've some free time, you may be more interested in doing this via Javascript. This will avoid submitting the page every single time, and process it live on the client-side.
Hey Triple_Nothing- perfectly acceptable question. I found my self asking the same thing, and would prefer to do it that way. However-If it is a school assignment and the instructions said we were not allowed to use javascript -___-
Posts: 7
Time spent in forums: 31 m 39 sec
Reputation Power: 0
Quote:
Originally Posted by Nanomech
What is the error you are getting?
Add the code above the doctype to the add.php file.
Regards,
NM.
hey sorry to bother you with a bunch of questions but I have one last one. How can I alter the code so the answer output states the answer but with each number. so if the user puts 1 and 2 and clicks add, the output would be 1 plus 2 = 3
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
The reason I wrote strval is because OP is new (and hopefully trying to actually learn rather than have us do her homework for her all semester) and strval() is the most explicit way of indicating that I wanted the string value of the sum to concatenate onto the string.
Posts: 9,791
Time spent in forums: 2 Months 3 Weeks 14 h 53 m 20 sec
Reputation Power: 6112
Omitting the curly braces in this particular instance won't break the code, but curly braces are always recommended when you're using variables. Not only does it make your code explicit, but it also allows code editors to highlight the code better and it prevents you from making a mistake like:
Further, curly braces are the only way to get certain kinds of variable interpolation to work properly. You can include $object->calls() inside strings, as well as $complex['array'][$access], both of which are best to enclose in curly braces.