Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 01-10-2005, 11:55 AM   #1 (permalink)
alandobinson
Registered User
 
Join Date: Jan 2005
Posts: 1
alandobinson is on a distinguished road
Need to add 2 number fields together in PHP

I am new to this - but have been trying to find a script to add 2 number fields together within a form using Frontpage. Any examples that I can use would be much appreciated.
alandobinson is offline   Reply With Quote
Old 01-10-2005, 12:24 PM   #2 (permalink)
falsepride
Regular Contributor
 
Join Date: Oct 2004
Posts: 229
falsepride is on a distinguished road
HTML Code:
<form action="process.php" method="post"> <input type="text" name="number1"> <input type="text" name="number2"> </form>
okay theres a form with just one text field. if you look at the first line, action is that page that the form data is being sent to. and method is either get or post. get means itll show the variables and thier names in the next pages url post wont do that.
PHP Code:
<?php

echo $_POST[number1] + $_POST[number2];

?>
echo simply outputs text to the browser. you could simply just do echo $number1; but if you dont have globals or something turned on in your php settings that script wont work. if you had your form set to get, then you would use echo $_GET[number1];
falsepride is offline   Reply With Quote
Old 01-10-2005, 06:17 PM   #3 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Really need to quote array keys to avoid possible issues with constants.

http://us4.php.net/manual/en/language.types.array.php

PHP Code:
echo $_POST['number1'] + $_POST['number2']; 
-r
idx is offline   Reply With Quote
Old 01-10-2005, 06:43 PM   #4 (permalink)
falsepride
Regular Contributor
 
Join Date: Oct 2004
Posts: 229
falsepride is on a distinguished road
i never use named constants, but i probably should have included that, just to stop him from getting into bad habbits that mite cause problems, my bad, alandobinson.
falsepride is offline   Reply With Quote
Old 01-10-2005, 06:56 PM   #5 (permalink)
idx
Senior Grasshopper
 
idx's Avatar
 
Join Date: Jun 2003
Location: FL
Posts: 317
idx is on a distinguished road
Yeah, I don't use them much either and when I do, they're pretty unique. (foo_app_VAR) PHP is pretty lax on that, so it should work, but as you said bad habits and that weird situation [in another app - in the future that may use foo_this as a constant] should be avoided.

-r
idx is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP to Flash control panel roccoman PHP 1 11-24-2004 09:10 AM
PHP vs .NET Redline Lounge 1 11-24-2004 07:10 AM
I need to learn PHP Nitro PHP 9 06-28-2003 12:24 PM
PHP - Hidden Fields and HREF's rockyracoon PHP 4 07-11-2002 11:33 PM


All times are GMT -8. The time now is 10:53 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0 RC8 ©2007, Crawlability, Inc.





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting