Recent Posts

XII Science SOP(PHP)

January 23, 2026

Server-Side Scripting (PHP)

 

SOP 1: Write a PHP program to check if a person is eligible to vote or not. The program should include the following.

·        Minimum age required for vote is 18.

·        Use Php functions.

·        Use Decision making statement.

age.html

<!DOCTYPE html>

<html>

<head>

<title></title>

</head>

<body>

<h1 align="center"> Person Eligible to vote or not</h1>

<form method="post" action="age.php">

Enter Your age

<input type="text" name="age"> <br> <br>

<input type="submit" name="submit" value="Check Eligible">

</form>

</body>  </html>

 Age.php

<?php

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

{

$age=$_POST['age'];

if($age>=18)

echo"<br> <br> You are Eligible to vote";

else

echo"<br><br> You are not Eligible to vote";

}

?>

SOP 2: Write a PHP function to count the total number of vowels (a,e,i,o,u) from the string. Accept a string by using HTML form.

Vowel.html

<!DOCTYPE html>

<html>

<head>  <title></title>  </head>

<body>

<h1 align="center">String Function</h1>

<form action="vowel.php" method="post">

Enter String :<input type="text" name="str"> <br>

<input type="submit" name="submit" value="Count Vowels">

</form>   </body>

</html>

Vowel.php

<?php

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

{

$str=strtolower($_POST['str']);

$vowels=array('a','e','i','o','u');

$len=strlen($str);

$num=0;

for($i=0;$i<$len;$i++)

{  if(in_array($str[$i],$vowels))

{

$num++;

} }

echo "Number of vowels : $num";  }  ?>

 

SOP 3: Write a PHP program to perform the following operations on an associative array.

·        Display elements of an array along with their keys.

·        Display the size of an array.

·        Delete an element from an array from the given index.

 Array.php

<?php

$m1=array("English"=>"55","Physics"=>"60","Chemistry"=>"70","Biology"=>"85");

echo "<b>Elements of an array along with their keys :</b>";

echo "<br><br>Your Score : ".$m1['English']." in English";

echo "<br><br>Your Score : ".$m1['Physics']." in Physics";

echo "<br><br>Your Score : ".$m1['Chemistry']." in Chemistry";

echo "<br><br>Your Score : ".$m1['Biology']." in Biology";

echo "<br><br><b>Size of an Array is : </b>".count($m1);

array_splice($m1,0,1);

echo "<br><br><b>After deleting array is : </b>";

foreach ($m1 as $x => $x_value) {

echo "<br><br>Key = ".$x." , Value = ".$x_value;

echo "<br>";

}

?>

SOP 4: Write a PHP program to save marks of English, Hindi, Marathi, Maths and Information Technology in an array. Display marks of individual subject along with total marks and percentage.

Array1.html

<!DOCTYPE html>


<html>

<head>

<title>SOP 4</title>

</head>

<body>


<?php

// 1. Store the marks in an associative array

$studentMarks = array(

    "English"                => 85,

    "Hindi"                   => 78,

    "Marathi"               => 82,

    "Maths"                  => 95,

    "Information Technology" => 92

);


// 2. Extract keys to allow numerical indexing in the traditional for loop

$subjects = array_keys($studentMarks); 


$totalMarks = 0;

$subjectCount = count($subjects);

$maxMarksPerSubject = 100; // Assuming each exam is out of 100


echo "--- Subject-wise Marks ---<br>";


// 3. Display individual marks using a traditional for loop

for ($i = 0; $i < $subjectCount; $i++) {

    $currentSubject = $subjects[$i];          // Get the subject name (key)

    $marks = $studentMarks[$currentSubject];  // Fetch the marks using the key

    

    echo $currentSubject . ": " . $marks . "<br>";

    $totalMarks += $marks;                    // Accumulate total marks

}


// 4. Calculate percentage

$totalPossibleMarks = $subjectCount * $maxMarksPerSubject;

$percentage = ($totalMarks / $totalPossibleMarks) * 100;


// 5. Display Results

echo "---------------------------<br>";

echo "Total Marks Obtained: " . $totalMarks . " / " . $totalPossibleMarks . "<br>";

echo "Percentage: " . number_format($percentage, 2) . "%<br>";

?>

</body>

</html>


SOP 5: Write a php program to save marks of English, Hindi, Marathi, Maths and Information Technology in an array for 5 students and display totals marks and percentage of each student s using ‘foreach’.


Marks.php

<!DOCTYPE html>

<html>

<head>

<title>SOP 5</title>

</head>

<body>

<?php

$marks=array("English"=>"60","Hindi"=>"78","Marathi"=>"74","Maths"=>"85","Information Technology"=>"96");

$t=0;

$x=0;

$c=count($marks);

foreach($marks as $x=>$x_value)

{

echo "<br><br> ".$x." = ".$x_value;

$t=$t+$marks[$x];

}

$p=$t*100/500;

echo "<br><br>Total is : $t";

echo "<br><br>Percentage is : $p";

?>

</body>

</html>

 

SOP 6: Write a program using PHP to calculate Electricity bill by accepting the limits.

·        For first 100 units - Rs. 4

·        For next 100 units - Rs. 5

·        For next all units - Rs. 6

Bill.html

<!DOCTYPE html>

<html>

<head>

<title>Bill Form</title>

</head>

<body>

<h1 align="center">Electricity Bill</h1>

<form method="post" action="bill.php">

Enter number of units : <input type="text" name="units" placeholder=""> <br>

<input type="submit" name="submit" value="Calculate Bills">

</form>

</body>

</html>

bill.php

<?php

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

{

$units=($_POST['units']);

if($units<=100)

{

$b=$units*4;

echo "Your bill amount is : ".$b;

}

else

{

if($units<=200)

{

$b=400+($units-100)*5;

echo "Your bill amount is : ".$b;

}

else

{

$b=400+500+($units-200)*6;

echo "Your bill amount is : ".$b;

}

}

}

?>


SOP 7: Write a program to insert a roll number and student name in a database (use postgresql data to create database). Accept roll number and name from the user.

Admission.php

<!DOCTYPE html>

<html>

<head lang="en">

<title>Home</title>

<meta name="viewport" content="width=device-width,initial-scale=1">

</head>

<body>

<h1>Student Admission Form</h1>

<form method="post">

Roll Number : <input type="text" name="rno" id="id_rno" maxlength="10" required placeholder="Enter your name"> <br>

Student Name: <input type="text" name="name" id="id_name" maxlength="30" required>

<input type="submit" name="submit" id="submit" value="Submit">

</form>

</body>

</html>


<?php

$servername ="pgsql:host=localhost;dbname=institute";

$username="postgres";

$password="123456";

$conn = new PDO($servername,$username,$password);

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

{

$rno = $_POST["rno"];

$name=$_POST["name"];

$sql="Insert into stud(rno,name) values($rno,'".$name."')";

$conn->exec($sql);

echo "New record created successfully.";

}

?>

Tags

About Author

Pankajkumar
Author - Pankajkumar

I am your guide.

No comments:

Post a Comment