Global Variable of PHP, Study notes of Computer Programming

Program based Global Variable of PHP for BCA and BSC(Computer Science)

Typology: Study notes

2022/2023

Available from 07/25/2023

sonia-baviskar
sonia-baviskar 🇮🇳

3 documents

1 / 13

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1. Write a PHP program to create a simple calculator that can accept two numbers and perform operations like add, subtract,
multiplication and divide (using Self Processing form).
<html>
<body>
<FORM ACTION="<?php $_SERVER['PHP_SELF']; ?>" method="POST">
<table>
<tr><td><h3>Enter first no :</td><td><input type=text name=no1 ></h3></td></tr>
<tr><td><h3>Enter second no :</td><td><input type=text name=no2></h3></td></tr>
<tr><td><b>Select Operation which u have to perform :</b></td>
<td><select name=cal>
<option value="1">Addition</option>
<option value="2">Substraction</option>
<option value="3">Multiplication</option>
<option value="4">Division</option>
</select></td></tr>
<tr><td></td><td><input type=submit name=submit value=Calculate></td></tr>
</table>
</form>
</body>
</html>
<?php
if(isset($_POST['submit']))
{
$no1=$_POST['no1'];
$no2=$_POST['no2'];
$cal=$_POST['cal'];
if((!empty($no1)) && (!empty($no2)))
{
switch($cal)
{
case 1:$add=$no1+$no2;
echo "<h1>addition=".$add."</h1>";
break;
case 2:$sub=$no1-$no2;
echo "<h1>subtraction=".$sub."</h1>";
break;
case 3:$mult=$no1*$no2;
echo "<h1>multiplication=".$mult."</h1>";
break;
case 4:$div=$no1/$no2;
echo "<h1>division=".$div."</h1>";
break;
}
}
else echo "<b>Please enter both 2 nos</b>";
}
else
die("not able to acccess");
?>
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Global Variable of PHP and more Study notes Computer Programming in PDF only on Docsity!

1. Write a PHP program to create a simple calculator that can accept two numbers and perform operations like add, subtract, multiplication and divide (using Self Processing form).

Enter first no : Enter second no : Select Operation which u have to perform :

addition=".$add.""; break;

case 2:$sub=$no1-$no2; echo "subtraction=".$sub.""; break;

case 3:$mult=$no1*$no2; echo "multiplication=".$mult.""; break;

case 4:$div=$no1/$no2; echo "division=".$div.""; break;

else echo "Please enter both 2 nos"; } else die("not able to acccess"); ?>

  1. A college has given roll number to each student, The roll number is six digit number where first two digits are faculty(B.Sc., BCA, BA) third digit is year (Ist(1), IInd(2) and IIIrd(3)) and last three digit are actual number. Write PHP script to accept a number and print faculty, year and roll number of student
Enter Your Roll No. format of Roll No: first two digits is 11 for B.sc., 12 for Bcom, 13 for BA<br />third digit

1/2/3 for respective yearlast three are for actual roll no.

Php file : ";

$fac=substr($roll_no,0,2); if($fac==11) echo "Faculty is B.Sc"; else if($fac==12) echo "Faculty is Bcom"; else if($fac==13) echo "Faculty is BA"; $year=substr($roll_no,2,1); if($year==1) echo "Year is First Year"; else if($year==2) echo "Year is Second Year"; else if($year==3) echo "Year is Third Year"; echo "Your Roll No. is".substr($roll_no,3)."";

. Write a Calculator class that can accept two values, then add them, subtract them, multiply them together, or divide them on request. For example: $calc = new Calculator( 3, 4 ); echo $calc- >add(); // Displays “7” echo $calc- >multiply(); // Displays “12” html file :

Enter No1 Enter No2

Name : Address : Mobile No :

Php file :

Enter LIC Information :

Policy no. : Policy Name : Premium :

Php file : Employee Details ";

echo "Name : ".$_COOKIE['emp1'].""; echo "Address : ".$_COOKIE['emp2'].""; echo "Mobile No. : ".$_COOKIE['emp3']."";

echo "Policy no. : ".$_POST['p_no'].""; echo "Policy Name : ".$_POST['p_name'].""; echo "Premium : ".$_POST['premium'].""; ?>

  1. Write a script to keep track of number of times the web page has been accessed(use $_COOKIE). php if(isset($_COOKIE['cnt'])) { $x=$_COOKIE['cnt']; $x=$x+1; setcookie('cnt',$x); } else { setcookie('cnt',2); echo "you accessed this page 1st^ time";

echo “You accessed this page $_COOKIE['cnt'] times”;

?>

  1. Write a PHP script for the following: Design a form to accept a number from the user. Perform the operations and show the results. **1) Factorial of a number using Recursion.
  1. Add the digits of that number to reduce it to single digit. (use the concept of self processing page.)**

slip12

{$sum=0; while($n) { $r=$n%10; $sum=$sum+$r; $n=$n/10; } $n=$sum; } return $n; } echo fact($_POST['txtnumber']); echo ""; echo singleval($_POST['txtnumber']); } ?>

echo "Capitalization of each word of each name :".ucwords($nm);

$e=explode('@',$eid);

If (count($e)==2) { echo "Email id contains @ symbol "; } else echo "email id doesn’t contains @ symbol or contains more @ symbol";

  1. Write a PHP script to accept a string and then display each word of string in reverse order. (use concept of self processing form) php file :

Enter String :

".$nstr; } ?>

20. Write PHP program to select list of subjects (use multivalued parameter) displays on next page. HTML File

Slip Select List of subjects

PHP File "; foreach($_GET['subjects'] as $s) { echo "$s"; }

?>

21. Write a PHP program for the followi2qang create a calculator that can store two values and perform operations like add, subtract, multiplication and divide (using Self Processing form) Php file :

Enter first no : Enter second no : Select Operation which u have to perform :

"; echo "$msg"; echo "";

  1. Write a PHP Script to display Server information in table format (Use $_SERVER).

"; foreach($_SERVER as $k=>$v) { echo"".$k."".$v.""; } echo""; ?>

  1. Create a login form with a username and password. Once the user logs in, the second form should be displayed to accept user details (name, city, phoneno). If the user doesn’t enter information within a specified time limit, expire his session and give a warning otherwise Display Details($_SESSION).

Html file :

Enter Username : Enter Password :

Php file :

slip_4-1.php :

enter ur details

Enter Name : Enter City :

Enter Phone No :

Invalid Username Or Password" ?>

slip_4-2.php : Page Time Expired"; else { echo "Name : ".$_REQUEST['uname'].""; echo "City : ".$_REQUEST['city'].""; echo "Phone NO : ".$_REQUEST['pno'].""; session_destroy(); } ?>

10. Create a form to accept student information (name, class, address). Once the student information is accepted, accept marks in next form (Java, PHP, ST, IT, pract1, and project). Display the mark sheet for the student in the next form containing name, class, marks of the subject, total and percentage(Use $_COOKIE).

Html file :

Enter Students information :

Name : Address : Class :

Php file : Slip_10-1.php :

Enter Marks for Student:

Enter Percentage

SLIP14_1.php

";

echo "Your Roll No Is : $_COOKIE[rno]";

echo "Your State Is : $_COOKIE[st]";

echo "Your City Is : $_COOKIE[ct]";

echo "Your Percentage Is : $_COOKIE[perc]";