473,413 Members | 1,733 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,413 software developers and data experts.

php is showing undefiened variable

hi
this is deepak, just beggner of learning php, facing some problem, if anyone could help me out, i will be thankful to him. when i run this code it will so me undefined variable as : calc , val1, and val2, which i have already declared in my html file.

my html code:
[HTML]
<html>
<head>
<title>Calculation form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form method="post" ACTION="calculate.php">
<P>Value 1: <INPUT TYPE="text" NAME="val1" SIZE=10></P>
<P>Value 2: <INPUT TYPE="text" NAME="val2" SIZE=10></P>
<P>Calculation:<br><br>

<INPUT TYPE="radio" NAME='calc' VALUE="add">add<br>
<INPUT TYPE="radio" NAME="calc" VALUE="subtract">subtract<br>
<INPUT TYPE="radio" NAME="calc" VALUE="multiply">multiply<br>
<INPUT TYPE="radio" NAME="calc" VALUE="divide">divide</P>


<P><INPUT TYPE="submit" NAME="Submit" VALUE="Calulate"></P>
</form>


</body>
</html>
[/HTML]
my php code:

[PHP]
<?php

$val1 = $_POST['val1'], $val2 = $_POST['val2'], $calc= &_POST['calc'];

if(($val1 == "") || ($val2 == "") || ($calc == "")){
header("Location: http://localhost/mySite/calculate_form.html");
exit;
}

if ($calc == "add"){
$result = $val1 + $val2;

} else if ($calc == "substruct"){
$result = $val1 - $val2;

} else if ($calc == "multiply"){
$result = $val1 * $val2;

} else if ($calc == "divide"){
$result = $val1 / $val2;
}
?>

<html>
<head>
<title>Untitled Document</title>
</head>

<body>
<P> The result of the claculation is: <? echo "$result"; ?> </P>
</body>
</html>
[/PHP]
Jul 19 '07 #1
3 1147
ak1dnar
1,584 Expert 1GB
There are some errors.Basically these are syntax errors.

In Html form: (read the lines carefully)
[HTML]<INPUT TYPE="radio" NAME="calc" VALUE="subtract">[/HTML]

In Php Script:

[PHP]else if ($calc == "substruct")[/PHP]

And here decalre the $_POST variables like this.
Expand|Select|Wrap|Line Numbers
  1. $val1 = $_POST['val1'];
  2. $val2 = $_POST['val2'];
  3. $calc= $_POST['calc'];

Instead of this,
Expand|Select|Wrap|Line Numbers
  1. $val1 = $_POST['val1'], $val2 = $_POST['val2'], $calc= &_POST['calc'];
  2.  
Jul 19 '07 #2
Thank very much ajaxrand, i have got the solution with your specified direction. now my script is working prperly.

thanks

Deepak Nagpal
Jul 20 '07 #3
ak1dnar
1,584 Expert 1GB
Thank very much ajaxrand, i have got the solution with your specified direction. now my script is working prperly.

thanks

Deepak Nagpal
Glad to hear that Deepak ! post back anytime when you have doubts.
-Thanks!
-Ajaxrand
Jul 20 '07 #4

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

Similar topics

1
by: Daniel Hill | last post by:
OK, I have very, VERY basic background knowledge of VB6 and have now upgraded to VB.NET and now I'm struggling to bring up the forms I want. What I am looking to do is to have a click a command...
5
by: Dré | last post by:
Hi, I'm making a FAQ-page. To keep it a little synoptic, only the questions are visible. When you klick on a certain question, the answer appears. You can find an example at:...
18
by: ashkaan57 | last post by:
Hi, how can I hide / show a section of a page when a link is clicked? Click on "show section" would show the section and change the link to "hide section", clicking on "hide section" would hide...
3
by: RC | last post by:
I can't quite grasp the concept of creating custom reports depending upon what options a user picks on a Form. For example, the user clicks on a "Print Reports" button and a Form pops up. On the...
5
by: Josh Golden | last post by:
3 forms. form 1, when button clicked instantiates form 2 which opens but is not shown. form 2 instantiates form 3 as showdialog. form 3 finishes, raises an event that form 2 catches. during the...
3
by: auron | last post by:
Hi there, I have a really stupid and banal problem with showing the results of a MySQL query in PHP, preciselly with MySQL count() function that gives to a variable in PHP the result. NOTE:...
7
by: underground | last post by:
I have a problem that I've spent countless hours on and I'm more than certain this is a obviuos issue to an expert but I am still learning. I have a paging script that I have modified to display a...
31
rpnew
by: rpnew | last post by:
Hi All, I'm working on one project in which i'm using PHP/MySql. And somewhere i'm using AJAX... XMLHttpResponse......... it works fine everywhere but when somewhere i dont know why it is not...
12
by: Arcticool | last post by:
Can anyone tell me why j never shows up in my locals window? 32 is printed to console so I know the assignment is working. I was under the impression that I could see everything as it happens by...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.