473,406 Members | 2,549 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,406 software developers and data experts.

problem integration php with html

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>
<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>

my php code:


<?php

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>
Jul 19 '07 #1
4 1415
code green
1,726 Expert 1GB
Assuming your php code is calculate.php then you need it to read the $_POST array as set when creating your form.
Expand|Select|Wrap|Line Numbers
  1. <form method="post" ACTION="calculate.php">
Before this [PHP]if(($val1 == "") || ($val2 == "") || ($calc == "")){[/PHP] you need [PHP]$val1 = $_POST['var1']; $val2 = $_POST['val2']; $calc = $_POST['calc'];[/PHP]
Jul 19 '07 #2
HI, code green

Thanx for helping me.but i don't know why the script is not running properly, as i did as per guidence by you the php file still showing me error which i am pasting exect keywords.

Error : PHP Notice: Undefined variable: calc in C:\Inetpub\wwwroot\mySite\calculate.php on line 6 PHP Notice: Undefined variable: calc in C:\Inetpub\wwwroot\mySite\calculate.php on line 9 PHP Notice: Undefined variable: calc in C:\Inetpub\wwwroot\mySite\calculate.php on line 12 PHP Notice: Undefined variable: calc in C:\Inetpub\wwwroot\mySite\calculate.php on line 15


I think now you r more comfortable with my problem.

thanks;
Jul 19 '07 #3
HI, code green

Thanx for helping me.but i don't know why the script is not running properly, as i did as per guidence by you the php file still showing me error which i am pasting exect keywords.

Error : PHP Notice: Undefined variable: calc in C:\Inetpub\wwwroot\mySite\calculate.php on line 6 PHP Notice: Undefined variable: calc in C:\Inetpub\wwwroot\mySite\calculate.php on line 9 PHP Notice: Undefined variable: calc in C:\Inetpub\wwwroot\mySite\calculate.php on line 12 PHP Notice: Undefined variable: calc in C:\Inetpub\wwwroot\mySite\calculate.php on line 15


I think now you r more comfortable with my problem.

thanks;
Jul 19 '07 #4
code green
1,726 Expert 1GB
I think you have not selected a radio button.
If a radio button is not set, it's $_POST element is not created.
Then the line
Expand|Select|Wrap|Line Numbers
  1. $calc = $_POST['calc'}; 
is pointing $calc to NULL (I think) so $calc is not defined.
Set a radio button to checked by default and it is better to test your $_POST variables first before using them.
Jul 19 '07 #5

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

Similar topics

1
by: Peter Schmiedeskamp | last post by:
Hello, I'm writing in regard to the distutils package for python. I regularly repackage installers for silent/automated distribution on numerous Windows PCs throughout an enterprise. Sites such...
4
by: Jakub Fast | last post by:
Hi, Does anybody know how far you can get nowadays with trying to use Python as the script language for XUL instead of JS? Is it possible (even theoretically) to write full-fledged applications...
8
by: rmacias | last post by:
I am maintaining an application that was writting in VB6 and has VBA 6.2 integrated into it. The VBA SDK allows the users of the application to generate VBA projects and scripts to gain access to...
2
by: Mantorok | last post by:
Hi I'm attempting to bind a Textbox.Text property to a custom object/property in C#. My form has an instance of my class in a property called Integration, I'm attempting to bind the textbox by:...
2
by: | last post by:
Is there an easy way to integrate Dreamweaver into VS.. Just a quick way to move the HTML of a web form into Dreamweaver for a bit to use it's features and then back into VS... Other than saving...
0
by: Stylus Studio | last post by:
Hey Everyone, A new podcast entitled: Business-to-Business Data Integration in a SOA World was just released by ZapThink. The key speakers in the podcast are the following: ZapThink...
1
by: sang | last post by:
Hi I prepared a program for Email Integration. That is email send to others through servlet's. I gave the code but it has some error in my code. Please check the code and give the feedback. ...
4
by: MarcoG | last post by:
Hi, I have an online application (written in .asp) that requires a login to be accessed and used. I have a login.asp page that asks for username and password, looks up in a MS SQL db if a...
5
by: Hussein B | last post by:
Hi. Please correct my if I'm wrong but it seems to me that the major continuous integration servers (Hudson, CruiseControl, TeamCity ..) don't support Python based application. It seems they...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.