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
omerfarooq123
Forum Newbie
Posts: 7 Joined: Thu Jul 09, 2009 3:27 am
Post
by omerfarooq123 » Thu Dec 24, 2009 8:54 am
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
omniuni
Forum Regular
Posts: 738 Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA
Post
by omniuni » Thu Dec 24, 2009 9:22 am
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.
AbraCadaver
DevNet Master
Posts: 2572 Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:
Post
by AbraCadaver » Thu Dec 24, 2009 9:31 am
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.
omniuni
Forum Regular
Posts: 738 Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA
Post
by omniuni » Thu Dec 24, 2009 9:40 am
Good Catch, Abra. I updated my code as you indicated.
AbraCadaver
DevNet Master
Posts: 2572 Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:
Post
by AbraCadaver » Thu Dec 24, 2009 10:31 am
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.
manohoo
Forum Contributor
Posts: 201 Joined: Wed Dec 23, 2009 12:28 pm
Post
by manohoo » Thu Dec 24, 2009 12:10 pm
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
Post
by omerfarooq123 » Fri Dec 25, 2009 4:07 am
Thanks a lot guyz for helping me out.. really i donot know before that $_post must be in capital Words like $_POST. Thanks