Fin PHP & Mys Assignment Report 1
Fin PHP & Mys Assignment Report 1
DAY -1
(01/05/2025)
2
antivirus application during the installation procedure. After
you have stopped the antivirus, select Yes to continue.
3
6. Select the folder to install XAMPP and click Next. It is
recommended to install the software into the default folder.
4
7. Untick the Learn more about Bitnami for XAMPP checkbox
and click Next.
5
8. Click Next to launch installation.
6
9. Wait until the process is finished.
7
10. Check that the Do you want to start the Control Panel
now? checkbox is ticked and click Finish.
8
11. After launching XAMPP Control Panel select Config to
open XAMPP settings.
9
12. Tick the Apache and MySQL checkboxes in the Autostart
of modules section and then click Save.
10
13. Click Quit to exit the panel and to apply changes.
11
14.Green background around Apache and MySQL marks that
these modules work correctly
12
14. In the browser address line enter localhost. If you see
the Welcome to XAMPP for Windows! notification, the
environment is set up and ready for work.
13
How to Start a New PHP Project in XAMPP?
• Before you run or start writing any program in PHP, you should
start Apache and MYSQL.
• After starting both servers, you have to write a program in
Notepad.
• After writing it, save that file as "program.php".
• Then copy that file program.php to C:/Program
Files/XAMPP/htdocs.
• Open the browser and type http://localhost.
• Now run your code in that browser.
14
3. Now, to see the script output, open the XAMPP control panel and
start Apache to host the local webserver, where our script will be
running.
15
DAY -2
(02/05/2025)
Note: The echo() function is not actually a function, so you are not required to
use parentheses with it. However, if you want to pass more than one
parameter to echo(), using parentheses will generate a parse error.
Tip: The echo() function is slightly faster than print().
Tip: The echo() function also has a shortcut syntax. Prior to PHP 5.4.0, this
syntax only works with the short_open_tag configuration setting enabled.
Variables in PHP
The correct way of declaring a variable in PHP:
$var_name = value;
16
A variable can have a short name (like $x and $y) or a more descriptive name
($age, $carname, $total_volume).
Rules for PHP variables:
• A variable starts with the $ sign, followed by the name of the variable
DAY -3
(03/05/2025)
if (condition) {
// code to be executed if condition is true;
}
17
if...else statement - use this statement to execute some code if a condition is
true and another code if the condition is false.
Syntax
if (condition) {
// code to be executed if condition is true;
} else {
// code to be executed if condition is false;
}
18
DAY -4
(04/05/2025)
PHP OPERATOR
The PHP arithmetic operators are used with numeric values to perform
common arithmetical operations, such as addition, subtraction,
multiplication etc.
Operators are used to perform operations on variables and values.
PHP divides the operators in the following groups:
• Arithmetic operators
• Assignment operators
• Comparison operators
• Increment/Decrement operators
• Logical operators
• String operators
• Array operators
• Conditional assignment operator
19
Arithmetic operators :- The PHP arithmetic operators are used
with numeric values to perform common arithmetical
operations, such as addition, subtraction, multiplication etc.
20
Xor Xor $ num1 xor $ num2 True if either $x or $y is true,
but not both
21
xor Xor $x xor $y True if either $x or $y is
true, but not both
PHP Array Operators:- The PHP array operators are used to compare
arrays.
An array stores multiple values in one single variable.
Numeric array - An array with a numeric index.
Associative array - An array where each ID key is associated with a value.
Ex. Numeric Array: $fruits=array("Apple","Mango","Banana","Grapes");
22
Operator Name Example Result
DAY -5
(05/05/2025)
PHP Loops :-
Often when you write code, you want the same block of code to run over and
over again a certain number of times. So, instead of adding several almost
equal code-lines in a script, we can use loops.
Loops are used to execute the same block of code again and again, as long as
a certain condition is true.
23
In PHP, we have the following loop types:
• while - loops through a block of code as long as the specified condition is
true.
while statement
while (condition)
{
code to be executed;
}
• do...while - loops through a block of code once, and then repeats the loop
as long as the specified condition is true.
Loop – do…while Statement
do
code to be executed;
}while (condition);
code to be executed;
24
• foreach - loops through a block of code for each element in an array.
Loop – foreach statement
code to be executed;
DAY -6
(06/05/2025)
PHP Functions
25
function myMessage() {
echo "Hello world!";
}
myMessage();
echo "Hello";
GET Variable
The built-in $_GET function is used to collect values from a form sent with
method="get".
Information sent from a form with the GET method is visible to everyone (it will
be displayed in the browser's address bar)
It has limits on the amount of information to send.
$_GET contains an array of variables received via the HTTP GET method.
There are two main ways to send variables via the HTTP GET method:
26
• Query strings in the URL
• HTML Forms
POST Variable
The built-in $_POST function is used to collect values from a form sent with
method="post".
Information sent from a form with the POST method is invisible to others and
has no limits on the amount of information to send.
$_POST contains an array of variables received via the HTTP POST method.
There are two main ways to send variables via the HTTP Post method:
• HTML forms
• JavaScript HTTP requests
27
DAY -7
(07/05/2025)
MySQL
MySQL (Part 1)
An Introduction to the PHPMyAdmin Interface. Creating a New Database Crea
ting a new Table and entering the value of the field with the requisite datatype.
SQL Query displayed in the PHPMyAdmin window.
MySQL (Part 2)
Connecting to the database and inserting dummy data into the
database.mysql_connect("server_addr", "username", "password") - Connect
to the Database Server with the authorised user and
password.mysql_select_db("database_name") - Selecting a database within a
connected database server.
MySQL (Part 3)
Writing some data into the database (INSERT and UPDATE Queries).
mysql_query('TYPE_HERE_YOUR_MYSQL_QUERY') - This function is used to
run specific queries on our database.
INSERT QUERY - INSERT into table values ('att1', 'att2' , 'att3', 'att4' ,'att5')
//Inserts Data into the table
28
UPDATE QUERY - UPDATE table_name SET att1='xyz' //Updates the Existing
values stored in the table of the database.
MySQL (Part 4)
Getting data from the database table and displaying it.
SELECT QUERY - SELECT * FROM table_name WHERE att1='abc' // Query
returns the value from the database where att1 = abc
mysql_num_rows() - Gives us the number of rows there are in the query we
have just given out.
ORDER BY - Helps to order the output result as when selecting the values form
the database. Use of DESC for Descending ordering / ASC for Ascending
ordering
MySQL (Part 5)
mysql_fetch_assoc — Fetch a result row as an associative array.
array mysql_fetch_assoc ( resource $result ) //Returns an associative array
that corresponds to the fetched row and moves the internal data pointer
ahead. mysql_fetch_assoc() is equivalent to calling mysql_fetch_array() with
MYSQL_ASSOC for the optional second parameter. It only returns an
associative array.
MySQL (Part 6)
Getting data from the database with the help of an HTML form.
Creating a FORM where a user can specify a name and selecting the
appropriate value from the database.
MySQL (Part 7)
29
Changing the existing values of the databse table using HTML Forms.
Update unique records using the id than individual values.
MySQL (Part 8)
DELETE QUERY - To Delete the specific or all the entries of the Database.
DELETE FROM table_name WHERE field='xyz' // Deletes the entry from the
database where the field = xyz.
Counts how many users have viewed your page as per count of refresh button
clicked fopen("file_name","parameter") opens a file (Creates it if not
exists).parameter assigns the mode, w for writting mode, a for append mode
file_get_contents("file_name")- This function is used to obtain content from
the file. fwrite("file_name",variable) - This function writes into the file value
present in variable.
DAY -8
(08/05/2025)
30
mb_substr(string,starting_position,no_of_characters) - This function takes a
specific character from a string and a range of no of characters preceeding it.
explode("delimiter",string) -This function breaks down the string into a array.
Delimiter is used to know from where to break string.
implode(string,"delimiter") -This function joins the array into a string. Delimiter
is used to know how to join array elements.
nl2br() -This function prints the content in exactly same form as written. Used
in case for breaking lines.
DAY -9
(09/05/2025)
31
Upload file and get file related information like file name, file size, etc
Check for error messages after uploading file
Cookies (Part 1)
What are cookies
Set cookies using setcookie function
Understaing how to set expiry time of cookies
Read and print values from existing cookies
Print every cookie that we have stored
Cookies (Part 2)
Check if a cookie exists or not using isset
Unset a cookie when no longer required
Change the value of a existing cookie
Sessions
A PHP session variable is used to store information about, or change settings
for a user session.
Session variables hold information about one single user, and are available to
all pages in one application.
32
session_start() - Starting a PHP Session
$_SESSION['variable_name']=value - Stores the value in the Session variable.
session_stop() - Stopping a PHP Session
DAY -10
(10/05/2025)
MD5 Encryption
Calculates the MD5 hash of str using the RSA Data Security, Inc.'s MD5
Message-Digest Algorithm, and returns that hash (Its a one way encrypting
technique).
Syntax : string md5 ( string $str [, bool $raw_output = false ] )
Used in encrypting passwords and storing them in a database.
33
Create the mail "From:" header
Using a local or external mail server to send email
Using the ini_set() and ini_get() functions to set and read internal php
configuration options respectively
DAY -11
(11/05/2025)
34
mysql_fetch_assoc('query')- This function fetches required information from
the database in the form of array.
DAY -12
(12/05/2025)
35
mysql_connect("hostname", "username", "password") - Connect to the
Database Server with the authorized user and password.
mysql_select_db("database_name") - This selects a database within a
connected database server
mysql_query('TYPE_HERE_YOUR_MYSQL_QUERY') - It is used to run specific
queries on our database.Here it retrieves password of user logged in.
User Password Change Part 3
updating the new password in database.
mysql_query('TYPE_HERE_YOUR_MYSQL_QUERY') - It is used to run specific
queries on our database. Here it updates new password into database.
DAY -13
(13/05/2025)
User Registration
36
User Registration Part 4
Inserting inputed information from the user into the database table through
query.
mysql_connect("hostname", "username", "password") - Connect to the
Database Server with the authorized user and password.
mysql_select_db("database_name") - This selects a database within a
connected database server
mysql_query('TYPE_HERE_YOUR_MYSQL_QUERY') - It is used to run specific
queries on our database. Here it inserts different fields into the database
table.
User Registration Part 5
md5("parameter")- encrypts parameter into irreversible logical code.
Converting the password inputed from user to md5 encrypt form.
User Registration Part 6
Checking the username provided so that condition for duplicate username
can be avoided.
mysql_query('TYPE_HERE_YOUR_MYSQL_QUERY') - This is used to run
specific queries on our database. Here it checks if username already exists in
database.
mysql_num_rows('query') - This function is used to counts no of rows retieved
from the query.
strtolower(string) - converts all characters of string into lower case.
37
ASSIGNMENT NO 1
1. Create a page evenodd.php into root directory of your local web server. Here, write a
script for finding out whether it is an odd number or even number and echo on the screen.
The following numbers set can be taken as input: 11, 23, 72 and 44.
Answer:
<html>
<body>
<?php
$numbers=array(11,23,72,44);
foreach($numbers as $value)
{
if($value%2==0)
{
echo "The Number $value is an Even number<br>";
}
else
{
echo "The Number $value is an Odd number<br>";
}
}
?>
</body>
</html>
Output:
1|Page
2. Create a page vowel.php into root directory of your local web server. Write in the script
for determining whether or not the character associated with a variable is Vowel or a
Consonant. If it’s a Vowel echo out the name of the vowel otherwise echo out its a
Consonant. Use Switch for this script.
Answer:
<html>
<body>
<?php
$ch = 'a';
switch ($ch)
{
case 'a':
case 'A':
echo " $ch is vowel";
break;
case 'e':
case 'E':
echo "$ch is vowel";
break;
case 'i':
case 'I':
2|Page
case 'u':
case 'U':
echo "$ch is vowel";
break;
default:
echo "$ch is consonant";
break;
}
?>
</body>
</html>
Output:
3|Page
II) PHP Operators
1. Write a PHP Script to declare 2 variables with specific numeric value of your choice and
Perform the following operations: Addition, Subtraction, Multiplication and Division. Also
echo out the Result on the screen.
Answer:
<html>
<body>
<?php
$a=10;
$b=2;
echo "Addition is: ".$a+$b."<br>";
echo "Substraction is: ".$a-$b."<br>";
echo "Multiplication is: ".$a*$b."<br>";
echo "Division is: ".$a/$b;
?>
</body>
</html>
Output:
4|Page
2. Write a PHP Script to declare 2 variables with specific numeric value of your choice and
find out the greater number between the two. If the numbers are equal, the respective
message must appear on the screen.
Answer:
<html>
<body>
<?php
$num1=12;
$num2=10;
if($num1==$num2)
{
echo "$num1 is equal to $num2";
}
else if($num1>=$num2)
{
echo "$num1 is greater";
}
else
{
echo "$num2 is greater";
}
?>
</body>
</html>
Output:
5|Page
III) Arrays
1. Declare an array week and assign the value of the days to each index number in the order
of occurrence and echo the result on the screen.
Answer:
<html>
<body>
<?php
$week=array(1=>"Monaday",2=>"Tuesday",3=>"wednesday",4=>"Thursday",5=>"Friday",6
=>"Saturday",7=>"Sunday");
echo $week[1]."<br>";
echo $week[2]."<br>";
echo $week[3]."<br>";
echo $week[4]."<br>";
echo $week[5]."<br>";
echo $week[6]."<br>";
echo $week[7]."<br>";
?>
</body>
</html>
Output:
6|Page
2. Write a PHP script to add the two 2x2 Matrices and output the result.
Answer:
<html>
<body>
<?php
$one=array( array(6,2),array(11,3));
$two=array (array(5,3),array(4,3));
for($i=0;$i<2;$i++)
for($j=0;$j<2;$j++)
echo "<br>";
?>
</body>
</html>
Output:
7|Page
IV) Loops
1. Write a PHP Script to print the following pattern on the Screen:
*****
****
***
**
*
Answer:
<html>
<head>
<title>loop</title>
<head>
<body>
<?php
for($i=5;$i>0;$i--)
for($j=1;$j<=$i;$j++)
echo "*";
echo "<br>";
?>
</body>
</html>
8|Page
Output:
2. Declare an array variable "x" assigning it with three elements "one, two and three" and Use
for each loop to print the values of the given array.
Answer:
<html>
<head>
<title>foreach</title>
<head>
<body>
<?php
$x=array("one","two","three");
foreach($x as $value)
{
echo $value."<br>";
}
?>
</body>
</html>
Output:
9|Page
V) Functions
1. Declare and define a function named writeName and within it echo out: Krupa
2. Now call the function to retrieve the following output: My name is Krupa
Answer:
<html>
<body>
<?php
function writeName($name)
{
echo "My Name is $name";
}
writename("Krupa ");
?>
</body>
</html>
Output:
10 | P a g
e
3. Declare a function named writeName2 with a parameter $firstname and define it by
echoing out:
$firstname." Sharma". Now call the function to retrieve the following output:
Answer:
<html>
<head>
<title>function2</title>
</head>
<body>
<?php
$firstname=array(1=>"Jai",2=>"Ram");
function writename2($firstname)
{
echo "MY name is ".$firstname[1]." Sharma"."<br>";
echo "MY Brother's name is ".$firstname[2]." Sharma"."<br>";
}
writename2($firstname);
?>
</body>
</html>
Output:
11 | P a g
e
VI) PHP Special Variables and PHP and HTML
1. If the three sides of a triangle are entered by the user, write a program to check whether the
triangle is isosceles, equilateral, scalene or right angled triangle. Use the 'Get' method to post
the form.
Answer:
<html>
<form action='GET.php' method='GET'>
<h4 style="color:red;">enter side1</h4>
<input type='text' name='side1'><br>
<h4 style="color:red;">enter side2</h4>
<input type='text' name='side2'><br>
<h4 style="color:red;">enter side3</h4>
<input type='text' name='side3'><br>
<h4 style="color:blue;">please click below button to submit:!!</h4>
<input type='submit' value='click here'>
</form>
</html>
<?php
error_reporting(E_ALL);
$side1=$_GET['side1'];
$side2=$_GET['side2'];
$side3=$_GET['side3'];
if($side1 && $side2 && $side3)
{
if($side1!=$side2 && $side1!=$side3 && $side2!=$side3)
{
echo "This is scalane triangle";
}
else if($side1==$side2 && $side1==$side3 && $side2==$side3)
{
echo "This is equilateral triangle";
}
else
{
echo "This is isosceles triangle";
}
}
12 | P a g
e
else
{
echo "please fill all boxes";
}
?>
Output:
2. Create a php page and create a user form which asks for marks in five subjects out of 100
and then displays the marksheet of the student. The format is as follows:
Name of Student*:
Marks in Each Subject
Subject 1* :
Subject 2* :
Subject 3* :
Subject 4* :
Subject 5* :
Note: All the entries marked (*) are to be input by the user. And use a submit button to post
the entries in the form using the POST method.
13 | P a g
e
Answer:
<html>
<head>
<title>MARKSHEET |Krupa kasar</title>
</head>
<body>
<form action='post.php' method='POST'>
<b><p style="color:red;">enter student name :<input type='text' name='Name'></p>
<p style="color:red;">enter 1st subject marks :<input type='text' name='sub1'></p>
<p style="color:red;">enter 2nd subject marks :<input type='text' name='sub2'></p>
<p style="color:red;">enter 3rd subect marks :<input type='text' name='sub3'></p>
<p style="color:red;">enter 4th subject marks :<input type='text' name='sub4'></p>
<p style="color:red;">enter 5the subject marks :<input type='text' name='sub5'></p>
<p style="color:blue;">please click button to submit:!!<input type='submit' value='click
here'></p></b>
<?php
$Name=$_POST['Name'];
$sub1=$_POST['sub1'];
$sub2=$_POST['sub2'];
$sub3=$_POST['sub3'];
$sub4=$_POST['sub4'];
$sub5=$_POST['sub5'];
if($Name && $sub1 && $sub2 && $sub3 && $sub4 && $sub5)
{
echo "Name of Student*: ".$Name."<br>";
echo "marks in each subject:<br>";
echo "Subject 1*: ".$sub1."<br>";
echo "Subject 2*: ".$sub2."<br>";
echo "Subject 3*: ".$sub3."<br>";
echo "Subject 4*: ".$sub4."<br>";
echo "Subject 5*: ".$sub5."<br>";
$total=($sub1+$sub2+$sub3+$sub4+$sub5);
echo "totals mark obtained: ".$total."<br>";
echo "Total Marks: 500<br>";
echo "percentage: ".($total/5);
}
14 | P a g
e
else
{
echo "please fill all details<br>";
}
?>
</form>
</body>
</html>
Output:
15 | P a g
e
ASSIGNMENT NO 2
MYSQL
1. Create a php page and create a user form which asks for marks in five subjects out of 100
and then displays the mark sheet of the student. The format is as follows:
Name of Student*:
Marks in Each Subject
Subject 1* :
Subject 2* :
Subject 3* :
Subject 4* :
Subject 5* :
Total Marks Obtained:
Total Marks:
Percentage:
Answer:
<html>
<head>
<title>MARKSHEET |Krupa kasar</title>
</head>
<body>
<form action='post.php' method='POST'>
<input type='text' name='Name'><br>
<input type='text' name='sub1'><br>
<input type='text' name='sub2'><br>
<input type='text' name='sub3'><br>
<input type='text' name='sub4'><br>
<input type='text' name='sub5'><br>
<input type='submit' value='click here'></p><br>
<?php
require("connect.php");
$Name=$_POST['Name'];
$sub1=$_POST['sub1'];
$sub2=$_POST['sub2'];
$sub3=$_POST['sub3'];
16 | P a g
e
$sub4=$_POST['sub4'];
$sub5=$_POST['sub5'];
$total_marks=500;
if($Name && $sub1 && $sub2 && $sub3 && $sub4 && $sub5)
{
echo "Name of Student*: ".$Name."<br>";
echo "marks in each subject:<br>";
echo "Subject 1*: ".$sub1."<br>";
echo "Subject 2*: ".$sub2."<br>";
echo "Subject 3*: ".$sub3."<br>";
echo "Subject 4*: ".$sub4."<br>";
echo "Subject 5*: ".$sub5."<br>";
$total=($sub1+$sub2+$sub3+$sub4+$sub5);
echo "totals mark obtained: ".$total."<br>";
echo "Total Marks:$total<br>";
$percentage=($total/5);
echo "percentage:".$percentage;
mysqli_query($connect,"INSERT INTO class1 VALUES('
','$Name','$sub1','$sub2','$sub3','$sub4','$sub5','$total','$total_marks','$percentage')");
}
else
{
echo "please fill all details<br>";
}
?>
</form>
</body>
</html>
Output:
17 | P a g
e
2. In the previous assignment use the following data:Name: Rohan Marks in Subject(s):
55,66,77,88,76.
Now write a PHP Script to update the values in the database with the new marks in subject 5
as "99" and recalculating and updating database entries: total obtained and percent.
Answer:
<html>
<head>
<title>MARKSHEET |krupa kasar</title>
</head>
<body>
<form action='post.php' method='POST'>
<input type='text' name='Name'><br>
<input type='text' name='sub1'><br>
<input type='text' name='sub2'><br>
<input type='text' name='sub3'><br>
<input type='text' name='sub4'><br>
<input type='text' name='sub5'><br>
<input type='submit' value='click here'></p><br>
<?php
require("connect.php");
$Name=$_POST['Name'];
$sub1=$_POST['sub1'];
$sub2=$_POST['sub2'];
$sub3=$_POST['sub3'];
$sub4=$_POST['sub4'];
$sub5=$_POST['sub5'];
$total_marks=500;
if($Name && $sub1 && $sub2 && $sub3 && $sub4 && $sub5)
{
echo "Name of Student*: ".$Name."<br>";
echo "marks in each subject:<br>";
echo "Subject 1*: ".$sub1."<br>";
echo "Subject 2*: ".$sub2."<br>";
echo "Subject 3*: ".$sub3."<br>";
echo "Subject 4*: ".$sub4."<br>";
echo "Subject 5*: ".$sub5."<br>";
$total=($sub1+$sub2+$sub3+$sub4+$sub5);
echo "totals mark obtained: ".$total."<br>";
18 | P a g
e
echo "Total Marks:$total<br>";
$percentage=($total/5);
echo "percentage:".$percentage;
mysqli_query($connect,"UPDATE class1 SET sub1='$sub1' where name='Rohan'");
mysqli_query($connect,"UPDATE class1 SET sub2='$sub2' where name='Rohan'");
mysqli_query($connect,"UPDATE class1 SET sub3='$sub3' where name='Rohan'");
mysqli_query($connect,"UPDATE class1 SET sub4='$sub4' where name='Rohan'");
mysqli_query($connect,"UPDATE class1 SET sub5='$sub5' where name='Rohan'");
mysqli_query($connect,"UPDATE class1 SET mark_obtained='$total'
where name='Rohan'");
mysqli_query($connect,"UPDATE class1 SET percentage='$percentage'
where name='Rohan'");
}
else
{
echo "please fill all details<br>";
}
?>
</form>
</body>
</html>
Output:
BEFORE UPDATING:
19 | P a g
e
AFTER UPDATING:
20 | P a g
e
ASSIGNMENT NO 3
1 Simple Visitor Counter Implement a Simple Visitor Counter in the Assignment associated
with MYSQL.
Answer:
<html>
<head>
<title> counter</title>
</head>
<body>
<?php
$file=file_get_contents("count.txt");
$visitor=$file;
$visitorsnew= $visitor+1;
$filenew=fopen("count.txt","w");
fwrite($filenew,$visitorsnew);
?>
</body>
</html>
21 | P a g
e
Output:
2 Create a PHP Script which asks for user to enter some random string. Use the appropriate
string functions to display the following operation on the input string.
Count number of Characters in the string
. Breaking down a string into an array
Reverse the string
Convert all alphabetic characters in string to their lower-case form.
Convert all alphabetic characters in string to their upper-case form
Declare a substring and replace the content of substring into original string.
Answer:
<html>
<head>
<title> string1</title>
</head>
<body>
</form>
</body>
</html>
<?php
$string=$_GET['name'];
if($string)
?>
23 | P a g
e
Output:
3 Create a file upload for and once uploaded display the information of the file uploaded (Ex.
File Name and File Size).
Answer:
<head>
<title> upload</title>
</head>
<body>
<h3>upload file</h3>
24 | P a g
e
<?php
if(isset($_POST['submit']))
{
$name=$_FILES['file']['name'];
$type=$_FILES['file']['type'];
$size=$_FILES['file']['size'];
$temp=$_FILES['file']['tmp_name'];
$store="uploaded/".$name;
$error=$_FILES['file']['error'];
if($error>0)
{
die ("error uploading file $error");
}
else
{
move_uploaded_file($temp,$store);
echo "upload successfullly!!";
echo "name of file: ",$name,"<br>";
echo "size of file: ",$size,"<br>";
echo "type of file: ",$type,"<br>";
25 | P a g
e
Output:
4 Use the md5 function to encrypt the password entered by the user in a form which submits the
user name and the password of the user and stores the encrypted password along with the
username in a database named data1.
Answer:
<html>
<head>
<title>md5 function</title>
</head>
<body>
<form action="md5.php" method='POST'>
Username<input type='text' name='username'><br><br>
Password<input type='password' name='password'><br><br>
<input type='submit' name='submit' value='submit'>
</form>
26 | P a g
e
</body>
</html>
<?php
$server='localhost';
$user ='root';
$pass='';
$db='data1';
$conn=new mysqli($server,$user,$pass,$db);
if($conn->connect_error)
die('connection failed!!');
if(isset($_POST['submit']))
{
$username=$_POST['username'];
$password=md5($_POST['password']);
$sql="insert into user(username,password)values('$username','$password')";
if($conn->query($sql)==true){
echo 'record saved';
}
else{
echo "error",$sql,"<br>",$conn->query($sql);
}
}
$conn->close();
?>
output:
27 | P a g
e
5 Create a Feedback form which is used to take the feedback along with the following
Information: Name and Email ID. After the successful submission of the form by the user,
a mail is sent to the user thanking him for his feedback and another mail is to be sent to
the administrator consisting of the information provided by the user ie. Name, Email and
Feedback
Answer:
<html>
<form action="feedbackform.php" method="POST">
Name<br><input type="text" name="name"><br>
Email<br><input type="text" name="email"><br>
college name<br><input type="Text" name="college"><br>
rating<br><input type="Number" name="rating"><br><br>
<input type="submit" name="submit">
</form>
</html>
<?php
$name=$_POST["name"];
$email=$_POST["email"];
$collegename=$_POST["college"];
$rating=$_POST["rating"];
$sub="Rating feedback. ... ";
$msg="Thanks for your feedback";
$header="kasarkrupa@gmail.com ";
$ato="kasarkrupa@gmail.com ";
$asub="users feedbak. . ";
$amsg="Name:".$name."\n"."Email:".$email."\n"."College
Name:".$collegename."\n"."Rating:".$rating."\n";
$aheader="From:bhaskardhuri641@gmail.com";
if(mail($email,$sub,$msg,$header)&& mail($ato,$asub,$amsg,$aheader))
{
echo "mail successfuly sent to administrator"."<br>";
echo "mail successfuly sent to ".$email."<br>";
}
else
{
echo "mail not sended. .. !"."<br>";
28 | P a g
e
}?>
Output:
29 | P a g
e