You are on page 1of 10

Q1.Write a PHP script to demonstrate the use of an associative array.

<?php
/* First method to create an associate array. */
$student_one = array("Maths"=>95, "Physics"=>90,
"Chemistry"=>96, "English"=>93,
"Computer"=>98);

/* Second method to create an associate array. */


$student_two["Maths"] = 95;
$student_two["Physics"] = 90;
$student_two["Chemistry"] = 96;
$student_two["English"] = 93;
$student_two["Computer"] = 98;

/* Accessing the elements directly */


echo "Marks:";
echo "<br>";
echo "Marks of Student Two in Maths:" . $student_two["Maths"];
echo "<br>";
echo "Marks of Student Two in Physics:" . $student_two["Physics"];
echo "<br>";
echo "Marks of Student Two in Chemistry:" . $student_two["Chemistry"];
echo "<br>";
echo "Marks of Student One in English:" . $student_one["English"];
echo "<br>";
echo "Marks of Student One is Computer:" . $student_one["Computer"];
?>
Q2.Write a PHP script to demonstrate the use of string function.

<?php
$n1=35;
$n2=043;
$n3=0x23;
$str="going BACK he SAW THIS";
$str1="mumbai TO goa";

//function "chr()"
echo "The equivalent character for ASCII 35 in decimal is ";
echo chr($n1). "\n";
echo "<br>";

echo "The equivalent character for ASCII 043 in octal is ";


echo chr($n2);
echo "<br>";

echo "The equivalent character for ASCII 0x23 in hex is ";


echo chr($n3). "\n";

//function "ord()"
echo ord("twinkle");//ASCII value of 't';
echo "<br>";

//function "strtolower()"
$resstr=strtolower($str);
echo $resstr;
echo "<br>";

//function "strtoupper()"
$resstr1=strtoupper($str1);
echo $resstr1;
echo "<br>";

//function "strlen()"
echo strlen("hello");
echo "<br>";

//function "strrev()"
echo strrev($str);
?>
Q3.Write a PHP script to send the data from one page to another page.

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form action="Q3a.php" method="post">
First Name: <input type="text" name="fname"><br>
Last Name: <input type="text" name="lname"><br>
<input type="submit" name="submit">
</form>
</body>
</html>

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
welcome
<?php
echo $_POST["fname"];
?>

<?php
echo $_POST["lname"];
?>
</body>
</html>
Q5. Write a PHP script to perform CRUD operation.

Q1(home)
<!DOCTYPE html>
<html>
<head>
<title>Landing Page</title>
</head>
<body>
<h1>Select any option</h1>
<button><a href="q1insert.php">INSERT Record in Table</a></button>
<button><a href="q1update.php">UPDATE Record in Table</a></button>
<button><a href="q1delete.php">DELETE Record from Table</a></button>
<button><a href="q1display.php">DISPLAY Table Records</a></button>
</body>
</html>
Q1(delete)
<?php
if(isset($_GET['d'])){
$server="localhost";
$user="root";
$pwd="";
$dbase="aadil";

$conn=new mysqli($server,$user,$pwd,$dbase);
if(!$conn){
echo "No Connection";
}

$number=$_GET['t1'];

$query="delete from employee where number=$number";


$ress=mysqli_query($conn,$query);

if($conn->query($query)===TRUE){
echo "Record deleted successfully";
}else{
echo "Error Deleting record: ";
}
}
?>

<!DOCTYPE html>
<html>
<head>
<title>deletion</title>
</head>
<body>
<form>
Enter Number: <input type="text" name="t1"> <br> <br>
<input type="submit" name="d" value="deletion"> <br> <br> <br>
<button><a href="q1.php">Go to Main Page</a></button>
</form>
</body>
</html>
Q1(display)
<?php
$server="localhost";
$user="root";
$pwd="";
$dbase="aadil";

$conn=new mysqli($server,$user,$pwd,$dbase);

if(!$conn){
echo "Not Connected";
}

$query="select * from employee";


$ress=mysqli_query($conn,$query);

if($ress->num_rows > 0){


while($row=$ress->fetch_assoc()){
echo " || Number: " . $row["number"].
" || Name: " . $row["name"].
" || Contect: " . $row["contect"].
" || Post: " . $row["post"].
" || Salary " . $row["salary"].
"<br>";
}

}else{
echo "0 result";
}
?>

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<button><a href="q1.php">Go to Main Page</a></button>
</body>
</html>
Q1(insert)
<?php
if(isset($_GET['s'])){
$server="localhost";
$user="root";
$pwd="";
$dbase="aadil";

$conn=new mysqli($server,$user,$pwd,$dbase);

if($conn){
echo "connected";
}else{
echo "not connected";
}

$number=$_GET['t1'];
$name=$_GET['t2'];
$contect=$_GET['t3'];
$post=$_GET['t4'];
$salary=$_GET['t5'];

$query="insert into employee values($number,'$name',$contect,


'$post',$salary)";

$res=mysqli_query($conn,$query);
if(!$res){
echo "Record not inserted";
}
}
?>

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form>
Enter Number: <input type="text" name="t1"> <br> <br>
Enter Name: <input type="text" name="t2"> <br> <br>
Enter Contect: <input type="text" name="t3"> <br> <br>
Enter Post: <input type="text" name="t4"> <br> <br>
Enter Salary: <input type="number" name="t5"> <br> <br>
<input type="submit" name="s" value="Register"> <br> <br> <br>
<button><a href="q1.php">Go to Main Page</a></button>
</form>
</body>
</html>
Q1(insert)
<?php
if(isset($_GET['s'])){
$server="localhost";
$user="root";
$pwd="";
$dbase="aadil";

$conn=new mysqli($server,$user,$pwd,$dbase);

if($conn){
echo "connected";
}else{
echo "not connected";
}

$number=$_GET['t1'];
$name=$_GET['t2'];
$contect=$_GET['t3'];
$post=$_GET['t4'];
$salary=$_GET['t5'];

$query="insert into employee values($number,'$name',$contect,


'$post',$salary)";

$res=mysqli_query($conn,$query);
if(!$res){
echo "Record not inserted";
}
}
?>

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<form>
Enter Number: <input type="text" name="t1"> <br> <br>
Enter Name: <input type="text" name="t2"> <br> <br>
Enter Contect: <input type="text" name="t3"> <br> <br>
Enter Post: <input type="text" name="t4"> <br> <br>
Enter Salary: <input type="number" name="t5"> <br> <br>
<input type="submit" name="s" value="Register"> <br> <br> <br>
<button><a href="q1.php">Go to Main Page</a></button>
</form>
</body>
</html>

You might also like