PHP LAB

// php program to check palindrome.


<?php
function palindrome($n){
$number = $n;
$sum = 0;
while(floor($number)) {
$rem = $number % 10;
$sum = $sum * 10 + $rem;
$number = $number/10;
}
return $sum;
}
$input = 1235321;
$num = palindrome($input);
if($input==$num){
echo "$input is a Palindrome number";
} else {
echo "$input is not a Palindrome";
}
?>

// php to check temp.


<?php
$month_temp = "78, 60, 62, 68, 71, 68, 73, 85, 66, 64, 76, 63, 81,
76, 73,
68, 72, 73, 75, 65, 74, 63, 67, 65, 64, 68, 73, 75, 79, 73";
$temp_array = explode(',', $month_temp);
$tot_temp = 0;
$temp_array_length = count($temp_array);
foreach($temp_array as $temp)
{
$tot_temp += $temp;
}
$avg_high_temp = $tot_temp/$temp_array_length;
echo "Average Temperature is : ".$avg_high_temp."
";
sort($temp_array);
echo " List of five lowest temperatures :";
for ($i=0; $i< 5; $i++)
{
echo $temp_array[$i].", ";
}
echo "List of five highest temperatures :";
for ($i=($temp_array_length-5); $i< ($temp_array_length); $i++)
{
echo $temp_array[$i].", ";
}
?> 

// php for two-dimensional array


<?php
$array2D = array(
 array(7, 8, 9),
 array(4, 5, 6),
 array(1, 2, 3)
);
$value = $array2D[1][2];
echo $value;
?>


// PHP Program that create a class that holds properties, methods, functions and object.


<?php
class MyClass {
 public $name;
 public function sayHello() {
 echo "Hello, my name is {$this->name}.";
 }
}
function addNumbers($a, $b) {
 return $a + $b;
}
$myObject = new MyClass();
$myObject->name = "John Doe";
$myObject->sayHello();
$result = addNumbers(10, 5);
echo $result;
?>


// PHP script that show university name and logo and take student code name and stream.


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body align="center">
<?php
$username = "root";
$password = "";
$servername = "localhost";
$database = "php";
$con = mysqli_connect($servername,$username,$password,$database);
if(isset($_POST['submit']))
{
$code = $_POST['code'];
$name =$_POST['name'];
$stream = $_POST['stream'];
$query = "insert into std_info(code,name,stream) values('$code','$name','$stream')";

 $iquery = mysqli_query($con,$query);
}
?>

<h1>BRAINWARE UNIVERSITY</h1>
<img src="https://www.brainwareuniversity.ac.in/images/bwu-logo-full.png"></br></br>
<form method="POST">
<input type="text" name="code" placeholder="BWU/BCA/20/000"></br></br>
<input type="text" name="name" placeholder="Enter Your Name"></br></br>
<input type="text" name="stream" placeholder="BCA"></br></br>
<input type="submit" name="submit" value="LOGIN">
</form>
</body>
</html>


// PHP script that Link between University home page and students page. 


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<h2>CLICK HERE TO GO TO THE HOME PAGE OF BRAINWARE UNIVERSITY</h2>
<?php
echo '<form action="https://www.brainwareuniversity.ac.in/">
<input type="submit" value="CLICK HERE">
</form>
'
?>
</body>
</html>


//PHP script that show three sections NAME, AFFILATION AND ADDRESS (FOR BWU) with different colors. 


<!DOCTYPE html>
<html>
<head>
 <title>Sections with Different Colors</title>
 <style>
 .name-section {
 background-color: #ff9999; /* Light red */
 }

 .affiliation-section {
 background-color: #99ff99; /* Light green */
 }

 .address-section {
 background-color: #9999ff; /* Light blue */
 }
 </style>
</head>
<body>
 <?php
 $name = "John Doe";
 $affiliation = "ABC Company";
 $address = "123 Main Street, City, Country";
 ?>

 <div class="name-section">
 <h2>Name</h2>
 <p><?php echo $name; ?></p>
 </div>

 <div class="affiliation-section">
 <h2>Affiliation</h2>
 <p><?php echo $affiliation; ?></p>
 </div>

 <div class="address-section">
 <h2>Address</h2>
 <p><?php echo $address; ?></p>
 </div>
</body>
</html>


// Write a PHP script for login page


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body align="center">
<?php
$username = "root";
$password = "";
$servername = 'localhost';
$database = "php";
$con = mysqli_connect($servername,$username,$password,$database);
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$password = $_POST['password'];
$check_name = "select * from user_info where name = '$name'";
$query = mysqli_query($con,$check_name);
$name_count = mysqli_num_rows($query);
if($name_count)
{
echo "Login Successful";
}
}
?>
<form method="POST">
<input type="text" name="name" placeholder="Enter Your Name">
</br>
<input type="text" name="password" placeholder="Password">
</br>
<input type="submit" name="submit" value="LOGIN">
</form>
</body>
</html>

Post a Comment

Post a Comment (0)

Previous Post Next Post