• No results found

CREATION OF WEB APPLICATION USING PHP

In document Cs9228 Web Technology Lab Manual (Page 77-90)

AIM:

To create a calculator web appliction using php.

ALGORITHM :

Step1 : Start the program

Step2 : Create a php web page calc.php

Step3: Using form and input type tag create various buttons, textbox, radio button etc.

Step4: calcute the output for various option

Step5: using post method display the result in next page.

Step6: Stop the program.

Coding:

Calc.php:

<?php

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Calculator</title>

</head>

<body>

<?php

// basic calculator program function showForm() {

?>

All field are required, however, if you forget any, we will put a random number in for you. <br />

<table border="0">

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">

<tr>

<td>Number:</td>

<td><input type="text" maxlength="3" name="number" size="4"

/></td>

<td><input type="text" maxlength="4" name="number2" size="4"

/></td>

<input type="radio" name="opt" value="/" />/<br />

<td><input type="text" name="rounding" value="4" size="4"

maxlength="4" /></td>

<td><small>(Enter how many digits you would like to round

<td><input type="submit" value="Calculate" name="submit" /></td>

</tr>

</form>

</table>

<?php }

if (empty($_POST['submit'])) { showForm();

(int)$_POST['number2'] = rand(1,200);

if (strpbrk($_POST['number'],"-") and strpbrk($_POST['number2'],"0.") and

$_POST['opt'] == "^") {

$_POST[opt] " . (int)strip_tags($_POST['number2']) . " is $result.";

break;

case "-";

$result = (int)strip_tags($_POST['number']) - (int)strip_tags($_POST['number2']);

echo "The answer to " . (int)strip_tags($_POST['number']) . "

$_POST[opt] " . (int)strip_tags($_POST['number2']) . " is $result.";

break;

case "*";

$result = (int)strip_tags($_POST['number']) * (int)strip_tags($_POST['number2']);

echo "The answer to " . (int)strip_tags($_POST['number']) . "

$_POST[opt] " . (int)$_POST['number2'] . " is $result.";

break;

echo "The square root of " . (int)strip_tags($_POST['number']) . "

rounded to " . strip_tags($_POST[rounding]) . " digits is " . round($result,(int)$_POST['rounding']);

echo "<br />";

echo "The square root of " . (int)strip_tags($_POST['number2']) . "

rounded to " . strip_tags($_POST[rounding]) . " digits is " . round($sqrt2,(int)strip_tags($_POST['rounding']));

break;

case "^":

$result =

(int)strip_tags(pow($_POST['number'],$_POST['number2']));

$pow2 =

(int)strip_tags(pow($_POST['number2'],$_POST['number']));

echo (int)$_POST['number'] . "<sup>" . strip_tags($_POST[number2]) . "</sup> is " . $result;

echo "<br />";

echo (int)$_POST['number2'] . "<sup>" . strip_tags($_POST[number]) . "</sup> is " . $pow2;

break;

} } }

echo "<br />";

?>

<a href="calc.php">Go Back</a>

</body>

</html>

OUTPUT:

Result:

Thus the calculator web appliction using php is been developed succesfully.

CREATION OF WEB APPLICATION USING PHP

AIM:

To create a calculator web appliction using php.

ALGORITHM :

Step1: Start the program

Step2: Create a php web page contact.php

Step3: Using form and input type tag create various buttons, textbox, radio

button etc.

Step4: Get the necessary field from the user.

Step5: Using post method display the result in next page.

Step6: Stop the program.

Coding:

Contact.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<title>Web and Crafts</title>

<meta name="keywords" content="" />

<meta name="description" content="" />

<link href="style.css" rel="stylesheet" type="text/css" media="screen" />

</head>

<body><!-- #header-wrapper -->

<?php

$name = $_POST['name'];

$address = $_POST['address'];

$city = $_POST['city'];

$zip = $_POST['zip'];

$phonenumber = $_POST['phonenumber'];

$email = $_POST['email'];

$message = $_POST['message'];

$error=0;

if (isset($_POST['submit'])) {

if (eregi('http:', $notes)) { die ("Do NOT try that! ! ");

}

if(!$email == "" && (!strstr($email,"@") || !strstr($email,"."))) {

echo "<h2>Use Back - Enter valid e-mail</h2>\n";

$badinput = "<h2>Feedback was NOT submitted</h2>\n";

echo $badinput;

$error=1;

}

if(empty($name) || empty($phonenumber) || empty($email ) ||

empty($message)) {

echo "<h2>Use Back - fill in all required fields </h2>\n"; $error=1; }

if($error!=1){

$todayis = date("l, F j, Y, g:i a") ; $attn =

$subject ;

$subject = "mail from $email";

$message = stripcslashes($message);

$mailmessage = " $todayis [EST]

\n Subject: $subject \n Message: $message \n From:

$name ($email)\n City: $city\n Pin/Zip code: $zip\n PhoneNo: $phonenumber\n

"; $from ="From: $email \r\n";

echo "for your interest in our services. We will contact you soon <br>";

} else {

echo "Use Back and Fill all required fields !!";

} } else {

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"

enctype="multipart/form-data" id="form1">

<table cellspacing="0" cellpadding="2" width="100%" border="0"

class="text_main">

<tr>

<td align="right" valign="center"><strong><font color="#ff0000">*</font>&nbsp;Name : </strong></td>

<td align="left" valign="center"><input

style="WIDTH: 207px; HEIGHT: 22px" size="26" name="name"

/></td>

</tr>

<tr>

<td align="right" valign="center"><strong>Address :</strong></td>

<td align="left" valign="center"><textarea style="WIDTH: 205px;

HEIGHT: 80px" name="address" rows="6" cols="22"></textarea></td>

</tr>

<tr>

<td align="right" valign="center"><strong>City :</strong></td>

<td align="left" valign="center"><input

style="WIDTH: 205px; HEIGHT: 22px" size="26" name="city" /></td>

</tr>

<tr>

<td align="right" valign="center"><strong><font

color="#ff0000">*</font>&nbsp;Phone No :</strong></td>

<td align="left" valign="center"><input

style="WIDTH: 168px; HEIGHT: 22px" size="21"

name="phonenumber" /></td>

</tr>

<tr>

<td align="right" valign="center"><strong><font color="#ff0000">*</font>&nbsp;Email :</strong></td>

<td align="left" valign="center"><input

style="WIDTH: 207px; HEIGHT: 22px" size="26" name="email"

/></td>

</tr>

<tr>

<td align="right" valign="center"><strong><font

color="#ff0000">*</font>&nbsp;Your Message :</strong></td>

<td align="left" valign="center"><textarea style="WIDTH: 346px;

HEIGHT: 158px" name="message" rows="8" cols="37"></textarea></td>

</tr>

<tr>

<td valign="center" align="right"></td>

<td valign="center" align="left"><input type="submit" value="Send"

name="submit" />

</tr>

<tr>

<td align="right" valign="center"></td>

<td align="left" valign="center">Fields marked <font color="#ff0000">*</font> are mandatory</td>

</tr>

</table>

</form>

<?php }

?>

</body>

</html>

Sample output:

RESULT:

Thus the Php application has been developed and executed successfully.

In document Cs9228 Web Technology Lab Manual (Page 77-90)

Related documents