Program 1
<?php
function markCheck($number){
if($number>=20)
return "PASS";
else{
return"FAIL";
$myMark=20;
$result= markCheck($myMark);
echo "The Mark is $myMark you are $result";
?>
Program2
Index.php
<?php
session_start();
$message = isset($_SESSION['message']) ? $_SESSION['message'] : "";
echo "<h2>Message Passing Example</h2>";
echo "<form action='display.php' method='post'>";
echo " <label for='message'>Enter a message:</label>";
echo " <input type='text' name='message' id='message' required>";
echo " <input type='submit' value='Submit'>";
echo "</form>";
echo "<p><strong>Previous Message:</strong> $message</p>";
unset($_SESSION['message']);
?>
Display.php
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['message'])) {
$_SESSION['message'] = $_POST['message'];
header('Location: index.php');
exit();
?>
Program3
<?php
$string = "Good,Thing!";
$array = explode(", ", $string);
echo "Original String: $string<br>";
echo "Exploded Array: ";
print_r($array);
?>
Program4
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "21bca052";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
$sql = "SELECT id, name, grade FROM student";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
echo "id: {$row["id"]} - Name: {$row["name"]} - Grade: {$row["grade"]}<br>";
} else {
echo "0 results";
$conn->close();
?>
Program5
LOGIN.html
<html>
<head>
<title>College Registration Form</title>
</head>
<center>
<body bgcolor="lightblue">
<h2>College Registration Form</h2>
</center>
<form action="reg.php" method="POST">
Name:<br>
<input type="text" name="name" required><br>
Father's Name:<br>
<input type="text" name="father_name" required><br>
DOB:<br>
<input type="date" name="dob" required><br>
GENDER:<br>
<input type="radio" name="gender" value="male">male
<input type="radio" name="gender" value="female">female<br><br><br>
LANGUAGE:<br>
<select name="lang" multiple>
<option value="Tamil">Tamil</option>
<option value="English">English</option>
<option value="Telugu">Telugu</option>
<option value="Malayalam">Malayalam</option>
</select><br><br>
BLOOD GROUP:<br>
<input type="radio" name="blood">A+
<input type="radio" name="blood">B+
<input type="radio" name="blood">O+
<input type="radio" name="blood">AB+
<input type="radio" name="blood">OB+<br><br><br>
10TH MARK:<br>
<input type="number" name="sslc" placeholder="enter mark"><br>
12TH MARK:<br>
<input type="number" name="hsc" placeholder="enter mark"><br>
CHOOSE YOUR 12TH COURSE:<br>
<select name="hsccource">
<option value="CS Maths">CS MATHS</option>
<option value="BIOLOGY">BIOLOGY</option>
<option value="ARTS BM">ARTS BM</option>
<option value="ARTS CS"> ARTS CS</option>
<option value="OTHER">OTHER</option></select><br>
ADDRESS:<br>
<textarea name="address" cols="10" rows="5"></textarea><br>
Mobile Number:<br>
<input type="tel" name="mobile_number" pattern="[0-9]{10}"<br>
<br>
<br>
<br>
<input type="submit" value="Submit"><br>
</form>
</body>
</html>
Reg.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "21bca052";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
// Get form data
$name = $_POST['name'];
$father_name = $_POST['father_name'];
$dob = $_POST['dob'];
$gender = $_POST['gender'];
$lang = $_POST['lang'];
$blood_group = $_POST['blood'];
$sslc_mark = $_POST['sslc'];
$hsc_mark = $_POST['hsc'];
$hsc_course = $_POST['hsccource'];
$address = $_POST['address'];
$mobile_number = $_POST['mobile_number'];
// Insert data into the table
// enter your database query
$sql = "INSERT INTO clg_form (name, father_name, dob, gender, lang, blood_group, sslc_mark,
hsc_mark, hsc_course, address, mobile_number) VALUES ('$name', '$father_name', '$dob', '$gender',
'$lang', '$blood_group', $sslc_mark, $hsc_mark, '$hsc_course', '$address', '$mobile_number')";
if ($conn->query($sql) === TRUE) {
echo "Registration successful!";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
// Close the connection
$conn->close();
?>
Program6
<?php
$string = "This is a sample sentence.";
$tokens = explode(" ", $string);
echo "Original Sentence: $string<br>";
echo "Tokens:<br>";
foreach ($tokens as $token) {
echo "$token<br>";
?>
Program7
<?php
// Regular Expression
$str = "Hello, World!";
$pattern = "/world/i";
echo preg_replace($pattern,"SAN",$str) . "<br>";
// Hashing Functions
echo "Hai iam santhosh <br>" . hash('md5',"santhosh");
?>
Program8
<?php
echo "Today is " . date("Y/m/d") . "<br>";
echo "Today is " . date("Y.m.d") . "<br>";
echo "Today is " . date("Y-m-d") . "<br>";
echo "The time is " . date("h:i:sa");
?>
program9
<?php
session_start();
$_SESSION["favcolor"] = "blue";
$_SESSION["favfood"] = "briyani";
echo "Session variables are set.<br>";
echo "Favorite color is " . $_SESSION["favcolor"] . ".<br>";
echo "Favorite food is " . $_SESSION["favfood"] . ".";
?>
Program10
<?php
session_start();
$_SESSION['username'] = 'john_doe';
setcookie('user_id', '123', time() + 10, '/');
echo "Welcome, " . $_SESSION['username'] . "!<br>";
if (isset($_COOKIE['user_id'])) {
echo "Your user ID is: " . $_COOKIE['user_id'] . "<br>";
} else {
echo "User ID cookie not set.<br>";
session_destroy();
?>