<?php
$conn = mysql_connect("localhost","root","");
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
echo "connected successfully";
?>
<html>
<body>
<form name="book" action="bookdb.php" method="post">
Book name<input type="text" name="bn" />
Author name<input type="text" name="an" />
Price<input type="text" name="pr" />
<input type="submit" value="add new book">
</form>
</body>
</html>
<html>
<body>
<form name="book" action="SeletDB.php" method="post">
<input type="submit" value="Display All books in the database">
</form>
</body>
</html>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
echo "connected sucessfully";
mysql_select_db("mydb", $con);
$bn=$_POST['bn'];
$an=$_POST['an'];
$pr=$_POST['pr'];
$result = mysql_query("insert into book_name values('$bn','$an',$pr)");
mysql_close($con);
?>
<!DOCTYPE html>
<html>
<!--The setInterval() method repeats a given function at every given time-interval.
window.setInterval(function, milliseconds);-->
<body>
<p>A script on this page starts this clock:</p>
<p id="demo"></p>
<button onclick="clearInterval(myVar)">Stop time</button>
<script>
var myVar = setInterval(myTimer, 1000);
function myTimer() {
var d = new Date();
document.getElementById("demo").innerHTML = d.toLocaleTimeString();
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p>Click "Try it". Wait 3 seconds. The page will alert "Hello".</p>
<p>Click "Stop" to prevent the first function to execute.</(p>
<p>(You must click "Stop" before the 3 seconds are up.)</p>
<button onclick="myVar = setTimeout(myFunction, 3000)">Try it</button>
<button onclick="clearTimeout(myVar)">Stop it</button>
<script>
function myFunction() {
alert("Hello");
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<script>
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
var s = today.getSeconds();
document.getElementById("demo").innerHTML=m + ":" + s;
m = checkTime(m);
s = checkTime(s);
document.getElementById("demo1").innerHTML=m + ":" + s;
document.getElementById('txt').innerHTML =
h + ":" + m + ":" + s;
var t = setTimeout(startTime, 500);
}
function checkTime(i) {
if (i < 10) {i = "0" + i};
// add zero in front of numbers < 10
return i;
}
</script>
</head>
<body onload="startTime()">
<div id="txt"></div>
<!--<p id="demo"></p>
<p id="demo1"></p>-->
</body>
</html>
<?php
/*date(format,timestamp)*/
echo "Today is " . date("Y/m/d"). "<br>";
//l is for the day name
echo "Its a " . date("l"). "<br>";
//s --> seconds a-->am or pm
echo "The time is " . date("h:i:sa"). "<br>";
date_default_timezone_set("America/New_York");
echo "The time is " . date("h:i:sa");
?>
<!DOCTYPE HTML>
<html>
<head><title>formEg2</title>
<style>
.error {color: red;}
</style>
</head>
<body>
<?php
/*uses the html and php codein same file*/
$nameErr = $emailErr = "";
/*isset is required to check whether the form is submitted so that it will get submit value*/
/*_SERVER["REQUEST_METHOD"] is used to check whether the form is submitted with POST method so that the POST array will have values, not empty*/
if(isset($_POST['submit'])&&$_SERVER["REQUEST_METHOD"] == "POST") {
//empty function checks for empty
if (empty($_POST["name"])) {
$nameErr = "Name is required";
} else {
/*test_input function - trim($data) will strip unnecessary characters (extra space, tab, newline) from the user input data.
stripslashes($data) will remove backslashes () from the user input data.
htmlspecialchars($data) converts special characters to HTML entities.*/
$name = test_input($_POST["name"]);
echo "<h2>Your Input:</h2>";
echo $name;
}
if (empty($_POST["email"])) {
$emailErr = "Email is required";
} else {
$email = test_input($_POST["email"]);
echo "<br>";
echo $email;
}}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>PHP Form Validation Example</h2>
<p><span class="error">* required field.</span></p>
<form method="post" action="formEg2.php">
Name : <input type="text" name="name">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
E-mail: <input type="text" name="email">
<span class="error">* <?php echo $emailErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head><title>formEg3</title>
<style>
.error {color: red;}
</style>
</head>
<body>
<?php
$nameErr = $regnoErr = "";
if(isset($_POST["submit"])&& $_SERVER["REQUEST_METHOD"] == "POST") {
if (empty($_POST["name"])) {
$nameErr = "Name is required"; }
/*The preg_match() function searches a string for pattern, returning true if the pattern exists, and false otherwise.
^start of the line
$ end of the line
preg_match("/^[a-zA-Z]*$/",$var] ---> 0 if any special chars is present
preg_match("/^[a-zA-Z]*$/",$var] ---> 1 if only a-zA-Z is present*/
else if (!preg_match("/^[a-zA-Z]*$/",$_POST["name"])) {
$nameErr = "Only alphabets are allowed";}
else {
$name = test_input($_POST["name"]);
echo "<h2>Your Input:</h2>";
echo $name; }
if (empty($_POST["regno"])) {
$regnoErr = "Regno is required";}
else if (!preg_match("/^[a-zA-Z0-9]*$/",$_POST["regno"])) {
$regnoErr = "Only alpha numeric are allowed";}
else {
$regno = test_input($_POST["regno"]);
echo "<br>";
echo $regno;
}}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>PHP Form Validation Example</h2>
<p><span class="error">* required field.</span></p>
<form method="post" action="formEg3.php">
Name : <input type="text" name="name">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
Regno: <input type="text" name="regno">
<span class="error">* <?php echo $regnoErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head><title>formEg4_1</title>
<style>
.error {color: red;}
</style>
</head>
<body>
<?php
$valid=1;
$nameErr = $regnoErr = $phnoErr = $emailErr = "1";
$name = $regno = $phno = $email = "";
if(isset($_POST["submit"])&& $_SERVER["REQUEST_METHOD"]=="POST") {
$name = test_input($_POST["name"]);
$regno= test_input($_POST["regno"]);
$phno = test_input($_POST["phno"]);
$email = test_input($_POST["email"]);
if (empty($name)) {
$nameErr = "Name is required";
$valid=0; }
else {
if (!preg_match("/^[a-zA-Z]*$/",$name)) {
$nameErr = "Only alphabets are allowed";
$valid=0;}
}
if (empty($regno)) {
$regnoErr = "Regno is required";
$valid=0;}
else {
if (!preg_match("/^[a-zA-Z0-9]*$/",$regno)) {
$regnoErr = "Only alpha numeric are allowed";
$valid=0;}
}
if (empty($phno)) {
$phnoErr = "Ph no is required";
$valid=0;}
else {
if (!preg_match("/[0-9]{10}/",$phno)) {
$phnoErr = "Enter ten digit ph no";
$valid=0;}
}
if (empty($email)) {
$emailErr = "Email is required";
$valid=0;}
else {
if (!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/",$email)) {
$emailErr = "Enter a valid email addr";
$valid=0;}
}
if($valid==1) {
include('formEg4_2.php');
exit();
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<h2>PHP Form Validation</h2>
<p><span class="error">* required field.</span></p>
<form method="post" action="formEg4_1.php">
Name : <input type="text" name="name" value="<?php echo $name?>">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
Regno: <input type="text" name="regno" value="<?php echo $regno?>">
<span class="error">* <?php echo $regnoErr;?></span>
<br><br>
Ph no : <input type="text" name="phno" value="<?php echo $phno?>">
<span class="error">* <?php echo $phnoErr;?></span>
<br><br>
Email : <input type="email" name="email" value="<?php echo $email?>">
<span class="error">* <?php echo $emailErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
<?php
echo "<h2>Your Input:</h2>";
echo $_POST["name"].'<br>';
echo $_POST["regno"].'<br>';
echo $_POST["phno"].'<br>';
echo $_POST["email"].'<br>';
?>
<html>
<body>
<form action="submit.php" method="post">
Name: <input type="text" name="firstname"><br>
<br/>
Password: <input type="password" name="pwd">
<br/>
Gender*
<input type="radio" name="sex" value="male">Male<br>
<input type="radio" name="sex" value="female">Female<br/>
Date of birth*:<input type="date" name="bday"><br>
Qualification*<select name="Qu">
<option value="B.Sc">B.Sc</option>
<option value="B.Tech" selected>B.Tech</option>
<option value="M.Sc">M.Sc</option>
<option value="M.Tech">M.Tech</option>
</select><br/>
E-mail ID*: <input type="email" name="usremail"><br>
Years of Experience(Max-2)*<input type="number" name="exp" min="0" max="2" value="0"><br>
Age*:<input type="range" name="points" min="25" max="30"><br>
Select your favorite color: <input type="color" name="favcolor"><br/>
your website: <input type="url" name="homepage"><br>
Hobbies*
<input type="checkbox" name="vehicle" value="movies">Movies<br>
<input type="checkbox" name="vehicle" value="reading">Reading books<br/>
<input type="checkbox" name="vehicle" value="reading">Others<br/>
Address*:</br><textarea name="addr" rows="10" cols="20">
Permanent Address
</textarea><br/>
State*<input list="state" name="state">
<datalist id="state">
<option value="Tamil Nadu">
<option value="Andhra">
<option value="Delhi">
<option value="punjab">
<option value="kerala">
</datalist><br/>
<input type="submit">
</form>
</body>
</html>
<?php
$fn=$_POST['firstname'];
$sex=$_POST['sex'];
$bday=$_POST['bday'];
$Qu=$_POST['Qu'];
$usremail=$_POST['usremail'];
$exp=$_POST['exp'];
$points=$_POST['points'];
$favcolor=$_POST['favcolor'];
$addr=$_POST['addr'];
$state=$_POST['state'];
$vehicle=$_POST['vehicle'];
$homepage=$_POST['homepage'];
echo $fn;
echo "<br>";
echo $sex;
echo "<br>";
echo $bday;
echo "<br>";
echo $Qu;
echo "<br>";
echo $usremail;
echo "<br>";
echo $exp;
echo "<br>";
echo $points;
echo "<br>";
echo $favcolor;
echo "<br>";
echo $addr;
echo "<br>";
echo $state;
echo "<br>";
echo $vehicle;
echo "<br>";
echo $homepage;
?>
<?php
$startdate = strtotime("Saturday");
$enddate = strtotime("+6 weeks", $startdate);
echo "Next coming Saturdays are :";
while ($startdate < $enddate) {
echo date("M d", $startdate)."<br>";
$startdate = strtotime("+1 week", $startdate);
}
?>
<!DOCTYPE html>
<html>
<body>
<p> Date(): </P>
<p id="demo"></p>
<p> Date("October 13, 2014 11:13:00") </P>
<p id="demo1"></p>
<p> Date(86400000) milliseconds since January 1, 1970, 00:00:00 </P>
<p>Zero time is 01 January 1970 00:00:00 UTC.</p>
<p>The number is specified in milliseconds</p>
<p id="demo2"></p>
<p> Date(99, 5, 24, 11, 33, 30, 0) </P>
<p>year, month, day, hour, minute, second, and millisecond</P>
<p id="demo3"></p>
<script>
var d = new Date();
var d1 = new Date("October 13, 2014 11:13:00")
var d2 = new Date(0);
var d3 = new Date(99, 5, 24, 11, 33, 30, 0);
document.getElementById("demo").innerHTML = d;
document.getElementById("demo1").innerHTML = d1;
document.getElementById("demo2").innerHTML = d2;
document.getElementById("demo3").innerHTML = d3;
</script>
</body>
</html>
<html>
<!--getDate() Get the day as a number (1-31)
getDay() Get the weekday as a number (0-6)
getFullYear() Get the four digit year (yyyy)
getHours() Get the hour (0-23)
getMilliseconds()Get the milliseconds (0-999)
getMinutes() Get the minutes (0-59)
getMonth() Get the month (0-11)
getSeconds() Get the seconds (0-59)
getTime() Get the time (milliseconds since January 1, 1970)-->
<!--
setDate() Set the day as a number (1-31)
setFullYear() Set the year (optionally month and day)
setHours() Set the hour (0-23)
setMilliseconds() Set the milliseconds (0-999)
setMinutes() Set the minutes (0-59)
setMonth() Set the month (0-11)
setSeconds() Set the seconds (0-59)
setTime() Set the time (milliseconds since January 1, 1970)-->
<body>
<p>The internal clock in JavaScript starts at midnight January 1, 1970.</p>
<p>The getTime() function returns the number of milliseconds since then:</p>
<p id="demo"></p>
<p>The getFullYear() method returns the full year of a date:</p>
<p id="demo1"></p>
<p>The getDay() method returns the weekday as a number:</p>
<p id="demo2"></p>
<p>The setFullYear() method sets a date object to a special date.</p>
<p id="demo3"></p>
<p>The setDate() method sets the date of a month.</p>
<p id="demo4"></p>
<script>
var d = new Date();
var d1 = new Date(0);
document.getElementById("demo").innerHTML = d1.getTime();
document.getElementById("demo1").innerHTML = d.getFullYear();
document.getElementById("demo2").innerHTML = d.getDay();
d.setFullYear(2020, 0, 14);
document.getElementById("demo3").innerHTML = d;
d.setDate(20);
document.getElementById("demo4").innerHTML = d;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var today, someday, text;
today = new Date();
someday = new Date();
someday.setFullYear(2000, 0, 14);
if (someday > today) {
text = "Today is before January 14, 2100.";
} else {
text = "Today is after January 14, 2100.";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<!--
The window object allows execution of code at specified time intervals. These time intervals are called timing events. The two key methods to use with JavaScript are:
setTimeout(function, milliseconds)
Executes a function, after waiting a specified number of milliseconds.
setInterval(function, milliseconds)
Same as setTimeout(), but repeats the execution of the function continuously.-->
<p>Click "Try it". Wait 3 seconds, and the page will alert "Hello".</p>
<button onclick="setTimeout(myFunction, 3000);">Try it</button>
<script>
function myFunction() {
alert('Hello');
}
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p>A script on this page starts this clock:</p>
<p id="demo"></p>
<script>
var myVar = setInterval(myTimer, 1000);
function myTimer() {
var d = new Date();
//Return the time portion of a Date object as a string, using locale conventions
document.getElementById("demo").innerHTML = d.toLocaleTimeString();
}
</script>
</body>
</html>
<?php
getmyage("25-01-2011",1,"sanjana sree");
function getmyage($my_birth, $my_set, $name = null) {
$day = date('d');
// echo $day;
$year = date('Y');
// echo $year;
$month = date('m');
// echo $month;
$name = htmlspecialchars($name);
$found = 0;
for ($i = 0; $i < strlen($my_birth); $i++) {
if (preg_match('/[-]/', $my_birth[$i])) {
$found++;
}
}
if ($found != 2) {
exit("Error: unknown format!");
}
$temp_birth = explode('-', $my_birth);
print_r($temp_birth);
$my_day = $temp_birth[0];
if (($my_day <= 0) || ($my_day > 31) || (!isset($my_day))) {
exit("Error: the day must be from 1 to 31!");
}
$day_digit = strlen($my_day);
if (($day_digit <= 0) || ($day_digit > 2) || (!is_numeric($my_day))) {
exit("Error: the day must have 2 digits!");
}
$my_month = $temp_birth[1];
if (($my_month <= 0) || ($my_month > 12) || (!isset($my_month))) {
exit("Error: the month must be from 1 to 12!");
}
$month_digit = strlen($my_month);
if (($month_digit <= 0) || ($month_digit > 2) || (!is_numeric($my_month))) {
exit("Error: the month must have 2 digits!");
}
$my_year = $temp_birth[2];
$year_digit = strlen($my_year);
if (($year_digit <= 0) || ($year_digit > 4) || (!is_numeric($my_year)) || (!isset($my_year))) {
exit("Error: the year must have 4 digits!");
}
if ($my_year > $year) {
exit("Error: the BirthDay year must be less than current year!");
}
if (($my_set < 0) || ($my_set > 1) || (!isset($my_set))) {
exit("Error: the value for the BirthDay message must be 0 or 1!");
}
/* Adjust with your own values */
$my_msg1 = "Today I turn " . ($year - $my_year) . " years!"; // Set the message for your BirthDay
$my_msg2 = "Today $name turns " . ($year - $my_year) . " years!"; // Set the message for your BirthDay
/* Don't change anything here below */
if (($day == $my_day) && ($month == $my_month)) {
$my_age = $year - $my_year;
if ($my_set == 0) {
$my_msg = false;
} else {
if (empty($name)) {
echo "<script type=\"text/javascript\">alert(\"$my_msg1\");</script>";
} else {
echo "<script type=\"text/javascript\">alert(\"$my_msg2\");</script>";
}
}
} elseif (($day >= $my_day) && ($month >= $my_month)) {
$my_age = $year - $my_year;
} elseif (($day < $my_day) && ($month == $my_month)) {
$my_age = --$year - $my_year;
} elseif (($day < $my_day) && ($month > $my_month)) {
$my_age = $year - $my_year;
} else {
$my_age = --$year - $my_year;
}
echo $my_age;
return $my_age;
}
?>
<?php
$d1=strtotime("Oct 04");
$d2=ceil(($d1-time())/60/60/24);
echo "There are " . $d2 ." days until 4th of October.";
?>
<?php
$servername = "localhost"; $username = "username"; $password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
?>
<?php
$n = preg_match("/^[a-zA-Z]*$/",'aaaaa////');
echo $n;
?>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydb", $con);
$result = mysql_query("Select * from book_name");
echo "<table border='1'>
<tr>
<th>Book name</th>
<th>Author name</th>
<th>Price </th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['bookname']. "</td>";
echo "<td> " . $row['authorname']."</td> ";
echo "<td>" . $row['price']."</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
<?php
//Create a Date From a String
$d=strtotime("10:30pm April 15 2014");
echo "Created date is " . date("Y-m-d h:i:sa", $d)."<br>";
echo "<br>";
echo "<br>";
echo "Current date & time is :";
echo date("Y-m-d h:i:sa") . "<br>";
$d=strtotime("tomorrow");
echo "Tomorrow is :";
echo date("Y-m-d h:i:sa", $d) . "<br>";
echo "Next Saturday is :";
$d=strtotime("next Saturday");
echo date("Y-m-d h:i:sa", $d) . "<br>";
echo "+3 Months";
$d=strtotime("+3 Months");
echo date("Y-m-d h:i:sa", $d) . "<br>";
?>
unit-3
<?php
$food = array('fruits1' => 'orange', 'fruits2' =>'banana','fruits3' => 'apple');
foreach($food as $key=>$b)
echo $key." ".$b."<br>";
?>
<?php
//same as strstr but this is case-insensitive
$text = "Although he had help, Leon is the author this book.";
print("Full text: $text <BR>\n");
print("Looking for 'leon':" . stristr($text,"leon"));
?>
<?php
/*Find the first occurrence of "world" inside "Hello world!" and return the rest of the string*/
echo strstr("Hello world!arunkumar","world")."<br>";
echo strstr("Hello world!",111);
//ascii code of 'o' is 111
?>
<?php
/* strpos(string,find,start)*/
$text = "Hello, World!";
if(strpos($text," "))
{
print("There is space in '$text'<BR>\n");
}
print("World is at position ".strpos($text, "World") . "<BR>\n");
?>
<?php
//Finds the position of the last occurrence of a string inside another string //(case-sensitive)
$path = "/usr/local/apache";
//find last slash
$pos = strrpos($path, "/");
//print everything after the last slash
print(substr($path, $pos+1));
?>
<?php
$array1 = array(2, 4);
$array2 = array("a", "b", "color" => "green", "shape" => "trapezoid", 4);
$result = array_merge($array1, $array2);
print_r($result);
?>
<?php
$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_pop($stack);
print_r($stack);
?>
<?php
$stack = array("orange", "banana");
array_push($stack, "apple", "raspberry");
print_r($stack);
?>
<?php
$base = array("orange", "banana", "apple", "raspberry");
$replacements = array(0 => "pineapple", 4 => "cherry");
$replacements2 = array(0 => "grape");
$basket = array_replace($base, $replacements);
print_r($basket);
?>
<?php
$input = array("php", 4.0, "red"=>"r", "green"=>"g");
$result = array_reverse($input);
$result1 = array_reverse($input,true);
print_r($result);
echo "<br>";
print_r($result1)
?>
<?php
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red');
$key = array_search('green', $array); // $key = 2;
echo $key."<br>";
$key = array_search('red', $array); // $key = 1;
echo $key."<br>";
?>
<?php
//shift removes first element and returns as output
$stack = array("orange", "banana", "apple", "raspberry");
echo $fruit = array_shift($stack);
echo "<br>";
print_r($stack);
?>
<?php
//array_slice(array,start,length,preserve)
//-2 second last element
//true preserve, false reset - default
$input = array("a", "b", "c", "d", "e","f");
$output = array_slice($input, 2);// returns "c", "d", and "e"
print_r($output);
echo "<br>";
$output = array_slice($input, 0, 3); // returns "a", "b", and "c"
print_r($output);
echo "<br>";
// note the differences in the array keys
print_r(array_slice($input, 2, -1));
echo "<br>";
print_r(array_slice($input, 2, -1, true));
echo "<br>";
?>
<?php
$input = array("red", "green", "blue", "yellow");
array_splice($input, 2);
print_r($input);
// $input is now array("red", "green")
?>
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<?php echo 'Hello World!'; ?>
</body>
</html>
<?php
$food = array('fruits' => array('orange', 'banana', 'apple'),
'veggie' => array('carrot', 'collard', 'pea'));
//0 - Default. Does not count all elements of multidimensional arrays
//1 - Counts the array recursively (counts all the elements of multidimensional arrays)
// recursive count
echo count($food, COUNT_RECURSIVE); // output 8
// normal count
echo count($food); // output 2
?>
<?php
$number = array(1,2,3,4,5);
echo "Print the values of array<br>";
foreach($number as $b)
echo $b."<br>";
echo "Print the values along with index of array<br>";
foreach($number as $key=>$b)
echo "[".$key."]".$b."<br>";
?>
<?php
$array = array(
'fruit1' => 'apple',
'fruit2' => 'orange',
'fruit3' => 'grape',
'fruit4' => 'apple',
'fruit5' => 'apple');
while ($fruit_name = current($array)) {
if ($fruit_name == 'apple') {
echo key($array).'<br />';
}
next($array);
}
?>
<?php
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
krsort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
<?php
$fruits = array("d"=>"lemon", "a"=>"orange", "b"=>"banana", "c"=>"apple");
ksort($fruits);
foreach ($fruits as $key => $val) {
echo "$key = $val\n";
}
?>
<?php
$text="Hello World";
print(strtolower($text));
print(strtoupper($text));
?>
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
<?php
$first = "abc";
$second = "xyz";
if(strcmp($first, $second) == 0)
{
print("strings are equal");
}
else
{
print("strings are not equal");
}
?>
<?php
$text = "a short string";
print("'$text' is " . strlen($text) . "
characters long.");
?>
<?php
print(strrev("abcdefg"));
?>
<?php
$a = array(2, 4, 6, 8);
echo "sum(a) = " . array_sum($a) . "\n";
$b = array("a" => 1.2, "b" => 2.3, "c" => 3.4);
echo "sum(b) = " . array_sum($b) . "\n";
?>
<?php
session_start();
$room_num=strtoupper($_POST['roomnum']);
$room_capacity=$_POST['roomcapacity'];
settype($room_capacity,'integer');
if (isset($_SESSION['loginname']))
{
echo "<body background=\"pic2.jpg\"><font size =+2>";
if ($room_num <> "")
{
$con=mysql_connect("localhost","root","") or die(mysql_error());
$db = mysql_select_db("cat",$con) or die(mysql_error());
$query="insert into class (classnum,capacity,availability) values('".$room_num."',".$room_capacity. ",".$room_capacity.")";
$rec_set=mysql_query($query,$con) or die(mysql_error());
echo "<font size=+2 >Room Added</font>";
mysql_close($con);
}
else
{
echo "<font size=+3> Room number is empty pl check it</font>";
echo "<form action= \"add_exam_hall.php\">";
echo "<input type=submit value=\" CONTINUE\" style=\"width:200px; height:50px; font-size:100%;color:green\">";
echo "</font></form></html>";
}
echo "<form action= \"exam_hall_process.php\"><font size=+2>";
echo "<input type=submit value=\"<< MENU\" style=\"width:200px; height:50px; font-size:100%;color:green\">";
echo "</font></form></html>";
}
else
echo "<font size=+2> Sorry, You are not authorized user. Please <b>Login </b>properly";
?>
<?php
session_start();
if (isset($_SESSION['loginname']))
{
echo "<body background=\"pic2.jpg\"><font size=+2><form action=\"add_room.php\" method=post><b>";
echo "Enter Room Number: <input type = text name=\"roomnum\">";
echo "<br><br>Room Capacity: <input type=radio name =\"roomcapacity\" value =40 checked> 40";
echo "<input type=radio name =\"roomcapacity\" value =60> 60<br><br>";
echo "<input type=submit value=\"ADD ROOM\" style=\"width:200px; height:50px; font-size:100%;color:green\"></b></form></font>";
}
else
echo "<font size=+2> Sorry, You are not authorized user. Please <b>Login </b>properly";
?>
<?php
session_start();
if (isset($_SESSION['loginname']))
{
echo "<body background=\"pic2.jpg\">";
echo "<h1 align=center color=blue size =+2> EXAM HALL PROCESS</h1>";
echo "<br><hr><br>";
echo "<form action=\"view_exam_hall.php\">";
echo "<input type=submit value=\"VIEW EXAM HALL\" style=\"width:200px; height:50px; font-size:100%;color:green\">";
echo "</form>";
echo "<form action=\"add_exam_hall.php\">";
echo "<input type=submit value=\"ADD EXAM HALL\" style=\"width:200px; height:50px; font-size:100%;color:green\">";
echo "</form> <form action=\"modify_exam_hall.php\">";
echo "<input type=submit value=\"MODIFY EXAM HALL\" style=\"width:200px; height:50px; font-size:100%;color:green\"></form>";
echo "<form action=\"remove_exam_hall.php\">";
echo "<input type=submit value=\"REMOVE EXAM HALL\" style=\"width:200px; height:50px; font-size:100%;color:green\"> </form></font>";
echo "</BODY></HTML>";
}
else
echo "<font size=+2> Sorry, You are not authorized user. Please <b>Login </b>properly</font>";
?>
<html>
<head>
<title>CAT PROCESS, SCSE, VIT UNIVERSITY, VELLORE, TAMIL NADU, INDIA</title>
</head>
<frameset cols="25%,80%">
<frame src ="Login.html" name="leftframe"/>
<frame src= "right.html" name ="rightframe"/>
</frameset>
</html>
<html>
<STYLE>
font.nf
{
text-align:left;
line-height:17pt;
font-size: 18pt;
color:magenta;
}
</STYLE>
<body>
<font color=green size=+3>
Sign Up</font>
<font class= nf>
<form method=post action="login.php" align =center>
Name: <br><input type=text name="LoginName"><br>
Password: <br><input type =password name ="PassName"><br><br>
<input type=submit value="Login">
</font>
</form>
</body>
</htmL
<?php
session_start();
$username=$_POST['LoginName'];
$pwd=$_POST['PassName'];
$con=mysql_connect("localhost","root","") or die(mysql_error());
$db=mysql_select_db("cat",$con) or die(mysql_error());
$query="select * from admin where username = '".$username."' and password = '".md5($pwd)."'";
$rs=mysql_query($query,$con) or die(mysql_error());
if (mysql_num_rows($rs) == 1)
{
// HAS TO DISPLAY THE MENUS
echo "<font size=+1 color=black>";
$_SESSION["loginname"]=$username;
echo "Hi, $username<br>";
echo "<a href= exam_Data_Process.php target=rightframe>CAT DATA PROCESS</a><br><br>";
echo "<a href= Exam_Hall_Process.php target=rightframe>EXAM HALL PROCESS</a><br><br>";
echo "<a href= CAT_Document_Process.html target=rightframe>CAT DOCUMENT PROCESS</a><br><br>";
echo "<a href= Change_Password_Process.php target=rightframe>CHANGE PASSWORD</a><br><BR>";
echo "<a href= Logout.php> LOGOUT</a>";
}
else
echo "<html>Not authenticated please login again<br> <a href=login.html target=leftframe> Login</a></html>";
mysql_close($con) or die(mysql_error());
?>
<?php
session_start();
if (isset($_SESSION['loginname']))
{
echo "<body background=\"pic2.jpg\">";
echo "<h1 align=center color=blue size =+2> EXAM HALL PROCESS</h1>";
echo "<br><hr><br>";
$con=mysql_connect("localhost","root","") or die(mysql_error());
$db = mysql_select_db("cat",$con) or die(mysql_error());
$query = "select classnum,capacity from class order by classnum";
$class_rec_set=mysql_query($query) or die(mysql_error());
echo "<form action=\"modify_room.php\" method =post>";
echo "<font size=+2>Exam Halls: <br><select name=\"roomnum\" size=5> ";
while ($class_rec = mysql_fetch_assoc($class_rec_set))
echo "<option value='".$class_rec['classnum']."'> ". $class_rec['classnum'];
echo "</select>";
echo "<br>Capacity: <input type=radio name=\"roomcapacity\" value =40 checked>40";
echo "<input type=radio name=\"roomcapacity\" value =60 >60<br>";
echo "<input type = submit value =\"UPDATE\" style=\"width:200px; height:50px; font-size:100%;color:green\"></FORM>";
echo "<form action= \"exam_hall_process.php\">";
echo "<input type=submit value=\"<< CANCEL\" style=\"width:200px; height:50px; font-size:100%;color:green\">";
echo "</font></form></html>";
mysql_close($con);
}
else
echo "<font size=+2> Sorry, You are not authorized user. Please <b>Login </b>properly</font>";
?>
<?PHP
session_start();
echo "<body background =\"pic2.jpg\">";
if (isset($_POST['roomnum']))
{
$room_number =$_POST['roomnum'];
$room_capacity=$_POST['roomcapacity'];
settype($room_capacity,'integer');
if (isset($_SESSION['loginname']))
{
echo "<body background=\"pic2.jpg\">";
echo "<h1 align=center color=blue size =+2> EXAM HALL MODIFY PROCESS</h1>";
echo "<br><hr><br>";
$con=mysql_connect("localhost","root","") or die(mysql_error());
$db=mysql_select_db("cat",$con) or die(mysql_error());
$query="update class set capacity = ".$room_capacity." where classnum = '". $room_number. "'";
$update_rec_set= mysql_query($query,$con) or die(mysql_error());
echo "Updated ".$room_number."'s capacity as ".$room_capacity."<br>";
}
else
{
die( "<font size=+2> Sorry, You are not authorized user. Please <b>Login </b>properly</font>");
}
}
else
{
echo "</font><font size=+2> No room was selected. Pl select a room";
echo "<form action= \"modify_exam_hall.php\">";
echo "<input type=submit value=\"CONTINUE\" style=\"width:200px; height:50px; font-size:100%;color:green\">";
echo "</font></form></html>";
}
echo "<form action= \"exam_hall_process.php\">";
echo "<input type=submit value=\"<< MENU\" style=\"width:200px; height:50px; font-size:100%;color:green\">";
echo "</font></form></html>";
?>
<?php
session_start();
if (isset($_SESSION['loginname']))
{
echo "<body background=\"pic2.jpg\">";
echo "<h1 align=center color=blue size =+2> EXAM HALL PROCESS</h1>";
echo "<br><hr><br>";
$con=mysql_connect("localhost","root","") or die(mysql_error());
$db = mysql_select_db("cat",$con) or die(mysql_error());
$query = "select classnum,capacity from class order by classnum";
$class_rec_set=mysql_query($query) or die(mysql_error());
echo "<form action=\"remove_room.php\" method =post>";
echo "<font size=+2>Exam Halls: <br><select name=\"roomnum\" size=5> ";
while ($class_rec = mysql_fetch_assoc($class_rec_set))
echo "<option value='".$class_rec['classnum']."'> ". $class_rec['classnum'];
echo "</select><br>";
echo "<input type = submit value =\"REMOVE\" style=\"width:200px; height:50px; font-size:100%;color:green\"></FORM>";
echo "<form action= \"exam_hall_process.php\">";
echo "<input type=submit value=\"<< CANCEL\" style=\"width:200px; height:50px; font-size:100%;color:green\">";
echo "</font></form></html>";
mysql_close($con);
}
else
echo "<font size=+2> Sorry, You are not authorized user. Please <b>Login </b>properly</font>";
?>
<?PHP
session_start();
echo "<body background=\"pic2.jpg\">";
echo "<h1 align=center color=blue size =+2> EXAM HALL MODIFY PROCESS</h1>";
echo "<br><hr><br>";
if (isset($_POST['roomnum']))
{
$room_num=$_POST['roomnum'];
if (isset($_SESSION['loginname']))
{
$con=mysql_connect("localhost","root","") or die(mysql_error());
$db=mysql_select_db("cat",$con) or die(mysql_error());
$query ="delete from class where classnum = '".$room_num."'";
mysql_query($query,$con) or die(mysql_error());
echo "<font size=+2> $room_num Removed from list";
}
else
{
die( "</font><font size=+2> Sorry, You are not authorized user. Please <b>Login </b>properly </font>");
}
else
{
echo "</font><font size=+2> No room was selected. Pl select a room";
echo "<form action= \"remove_exam_hall.php\">";
echo "<input type=submit value=\"CONTINUE\" style=\"width:200px; height:50px; font-size:100%;color:green\">";
echo "</font></form></html>";
}
echo "<form action= \"exam_hall_process.php\">";
echo "<font size=+2><input type=submit value=\"<< MENU\" style=\"width:200px; height:50px; font-size:100%;color:green\">";
echo "</font></form></html>";
?>
<HTML>
<STYLE>
font.bf
{
text-align:center;
line-height:20pt;
font-size:24pt;
color:green
}
font.mf
{
text-align:center;
line-height:17pt;
font-size: 24pt;
color:blue;
}
</STYLE>
<BODY background ="pic2.jpg" align=center>
<br><br>
<font class=bf>
<h1>CAT EXAM PROCESS</h1></font>
<font class=mf>
<h2>SCSE</H2>
<H3>VIT UNIVERSITY,VELLORE</H3></font>
</BODY>
</HTML>
<?php
session_start();
if (isset($_SESSION['loginname']))
{
$con=mysql_connect("localhost","root","") or die(mysql_error());
$db = mysql_select_db("cat",$con) or die(mysql_error());
$query="select classnum,capacity from class order by classnum";
$class_rec_set = mysql_query($query,$con) or die(mysql_error());
echo "<body background=\"pic2.jpg\">";
echo "<form action= \"exam_hall_process.php\">";
echo "<input type=submit value=\"<< GO BACK\" style=\"width:200px; height:50px; font-size:100%;color:green\">";
echo "</font></form></b></html>";
echo "<h1 align=center><font color=blue>EXAM ROOM DETAILS</H1>";
echo "<font size=+2 color=maroon>";
echo "<table border=1 style =\"font-size:+25\" align=center><b><tr><th>S. No.</th><th> ROOM NUMBER</th><th> CAPACITY</th></tr>";
$count=0;
while($class_rec = mysql_fetch_assoc($class_rec_set))
{
$count++;
echo "<tr align=center><td>$count</td><td>",$class_rec['classnum'],"</td><td>",$class_rec['capacity'], "</td></tr>";
}
echo "</table><br><br>";
echo "<form action= \"exam_hall_process.php\">";
echo "<input type=submit value=\"<< GO BACK\" style=\"width:200px; height:50px; font-size:100%;color:green\">";
echo "</font></form></b></html>";
mysql_close($con);
} else
echo "<font size=+2> Sorry, You are not authorized user. Please <b>Login </b>properly";