Need help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
omerfarooq123
Forum Newbie
Posts: 7
Joined: Thu Jul 09, 2009 3:27 am

Need help

Post by omerfarooq123 »

As i am new in php field, i write a code but giving errors..

i create calculate.html and write this..
<form method="post" action="calculate.php">

<input type="text" name="val1" size="15" /> <br></br>
<input type="text" name="val2" size="15" /><br></br>
ADD <input type ="radio" name="calc" value ="add" /><br>
Sub <input type="radio" name ="calc" value ="sub" /><br>
Multiply <input type="radio" name="calc" value="multiply" /><br>
Divide <input type="radio" name="calc" value="divide" /><br><br>
<input type="submit" name="submit" value="Calculate" />
and then create "calculate.php" and there i write this
<?php
if ($_post[calc] == "add")
{
$result = $_POST[val1] + $_POST[val2];
}


echo $result;
?>
but it is not showing when i add 2 variables.please help me
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Need help

Post by omniuni »

POST is a keyed array.

Code: Select all

<?php
if ($_POST[calc] == "add")
{
$result = $_POST['val1'] + $_POST['val2']; //see the quotes?
}
 
 
echo $result;
?>
Last edited by omniuni on Thu Dec 24, 2009 9:40 am, edited 1 time in total.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Need help

Post by AbraCadaver »

Variables are case sensitive. I doubt there is a $_post array, so the if will never fire.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: Need help

Post by omniuni »

Good Catch, Abra. I updated my code as you indicated.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Need help

Post by AbraCadaver »

Update it again and quote the calc index ;-)
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: Need help

Post by manohoo »

The devil is in the details. Try this:

Code: Select all

 
<?php
if ($_POST["calc"] == "add")
{
$result = $_POST["val1"] + $_POST["val2"];
}
 
 
echo $result;
?>
Notice the quotes in $_POST["calc"] etc...
Also $_POST must be in upper case.
omerfarooq123
Forum Newbie
Posts: 7
Joined: Thu Jul 09, 2009 3:27 am

Re: Need help

Post by omerfarooq123 »

Thanks a lot guyz for helping me out.. really i donot know before that $_post must be in capital Words like $_POST. Thanks
Post Reply