473,385 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

sum of two numbers using php $_POST vars

How to write a program in a one page to find the sum of two numbers using php $_POST method.
Sep 15 '07 #1
3 7900
$_POST is an array of values, not a method.

Expand|Select|Wrap|Line Numbers
  1. $sum = array_sum($_POST);
  2.  
will total all values in post. If you're trying to be a bit more specific and sum all values from a form like this:

Expand|Select|Wrap|Line Numbers
  1. <form method="post">
  2. <input type="text" name="entry[]" /><br />
  3. <input type="text" name="entry[]" /><br />
  4. <input type="text" name="entry[]" /><br />
  5. <input type="text" name="entry[]" /><br />
  6. <input type="submit" value="Show Sum" /><br />
  7. </form
  8.  
then, you can calculate the value of all the entry tags by

Expand|Select|Wrap|Line Numbers
  1. $sum = array_sum($_POST['entry']);
  2. echo $sum;
  3.  
Sep 15 '07 #2
ak1dnar
1,584 Expert 1GB
How to write a program in a one page to find the sum of two numbers using php $_POST method.
Could you please elaborate your question with an example. This explanation is not enough to describe your problem scenario.

And Welcome to TheScripts.com.

Sep 15 '07 #3
ronverdonk
4,258 Expert 4TB
Changed the title of this thread to better describe the problem.

moderator
Sep 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jason | last post by:
Currently I have a number of html forms which loop through records in a database table. In order to be able to update the right record when the form is submitted, I've tacked number on to the...
2
by: Christian Decker | last post by:
I wanted to know if is a good idea to create classes that mirror exactly the structure of a database. This might sound a bit fuzzy but I'l explain myself with an example: CREATE TABLE...
5
by: jerrygarciuh | last post by:
Hello, I would like to set a variable to a default if 2 other vars are undef. Obviously there are several ways to do this but I would like to do it as I would in Perl: $memberState = $_POST ...
10
by: arun.kumar.varma | last post by:
Hi, I'm learning PHP and prepared a simple login form. validate.php does the validation and it was behaving erratically. So, I did var_dump of $_POST variable and it's NULL. Did I miss anything...
9
by: bissatch | last post by:
Hi, How would I go about destroying POST vars after their use in a script? Is this possible? The reason is that when I use a script that, for example, add a row to a database. If for some...
5
by: lbolognini | last post by:
Hi all, I was wondering if there's a technique to use POST instead of GET to send data back to a form so to refill it with user input after this hasn't passed validation. Any clues? ...
1
by: RDizzle | last post by:
okay. so all i am doing is changing a registration script that uses $_GET to a script that uses $_POST, but the validation script now returns NULL values for all posted vars. What's the deal? ...
1
George Lft
by: George Lft | last post by:
ok, first of all, i built my register page using dreamweaver tool which the codes haven been out of control. Now i'm thinking that turning over everything - by using this another set of codes. And...
7
by: gamernaveen | last post by:
I've been busy coding a signup system with PHP. There are 2 forms , form1 and form2. form1 contains: Name , Age , form 2 contains Username , Password , Repeat Pass , Email I use POST method...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.