0% found this document useful (0 votes)
26 views66 pages

Fin PHP & Mys Assignment Report 1

The document provides a comprehensive guide on installing and using XAMPP on Windows, including steps for setting up a PHP development environment. It covers various PHP programming concepts such as variables, operators, loops, functions, and MySQL database interactions. Additionally, it includes practical examples and syntax for executing PHP scripts and managing databases.

Uploaded by

diwanhitesh68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views66 pages

Fin PHP & Mys Assignment Report 1

The document provides a comprehensive guide on installing and using XAMPP on Windows, including steps for setting up a PHP development environment. It covers various PHP programming concepts such as variables, operators, loops, functions, and MySQL database interactions. Additionally, it includes practical examples and syntax for executing PHP scripts and managing databases.

Uploaded by

diwanhitesh68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

1

DAY -1
(01/05/2025)

How To: Install XAMPP on Windows


XAMPP is the most popular PHP development environment.
XAMPP is a completely free, easy to install Apache distribution containing
MariaDB, PHP, and Perl. The XAMPP open source package has been set up to
be incredibly easy to install and to use.

1. You can download XAMPP through the official


website, https://www.apachefriends.org/download.html.
OR
1. Go to the official XAMPP website and download the latest
version of XAMPP for Windows.

2. Launch XAMPP installer xampp–win32x.x.xxxxxx-


installer.exe.
3. Some antivirus applications might interfere in the XAMPP
installation process. So it is recommended to stop your

2
antivirus application during the installation procedure. After
you have stopped the antivirus, select Yes to continue.

4. Confirm that you will avoid installing the software


to C:\Program Files and press OK. User Account Control (UAC)
might block some XAMPP functions when installing
to C:\Program Files, so it is recommended to install XAMPP to
the default folder.

5. Select all components and then click Next.

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.

How to Run a PHP Code Using XAMPP?


Before running a PHP script, you must know where to write it.
In the XAMPP directory, there exists a folder called “htdocs”. This is
where all the programs for the web pages will be stored.
Now, to run a PHP script:
1. Go to “C:\xampp\htdocs” and inside it, create a folder. Let’s call it
“demo”. It’s considered good practice to create a new folder for
every project you work on.

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.

4. Now navigate to your browser and type in “localhost/demo/” in


the address bar to view the output.

15
DAY -2
(02/05/2025)

Echo PHP Function


Definition and Usage
The echo() function outputs one or more strings.
Syntax: echo(strings);
Ex.
<?php

echo "Hello World!";


?>

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

• A variable name must start with a letter or the underscore character


• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters and underscores (A-z,
0-9, and _ )
• Variable names are case-sensitive ($age and $AGE are two different variables)

DAY -3
(03/05/2025)

If and Switch Statements

if statement - use this statement to execute some code only if a specified


condition is true.
Syntax

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;
}

if...elseif....else statement - use this statement to select one of several


blocks of code to be executed.
Syntax
if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
// code to be executed if first condition is false and this condition is true;
} else {
// code to be executed if all conditions are 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.

Operator Name Example

+ Addition $num1 + $ num2

- Subtraction $ num1 - $ num

* Multiplication $ num1 * $ num2

/ Division $ num1 / $ num2

% Modulus $x num1 % $ num2

** Exponentiation $ num1 ** $ num2

PHP Comparison Operators :-


The PHP comparison operators are used to compare two values
(number or string):

Operator Name Example

20
Xor Xor $ num1 xor $ num2 True if either $x or $y is true,
but not both

== Equal $ num1 == $ num2

=== Identical $ num1 === $ num2

!= Not equal $ num1 != $num2

<> Not equal $ num1<> $num2

!== Not identical $x num1 !== $ num2

> Greater than $ num1 > $ num2

< Less than $ num1 < $ num2

>= Greater than or equal to $ num1 >= $ num2

<= Less than or equal to $ num1<= $ num2

PHP Logical Operators :-


The PHP logical operators are used to combine conditional statements.

Operator Name Example Result

and And $x and $y True if both $x and $y are


true

or Or $x or $y True if either $x or $y is true

21
xor Xor $x xor $y True if either $x or $y is
true, but not both

&& And $x && $y True if both $x and $y are


true

|| Or $x || $y True if either $x or $y is true

! Not !$x True if $x is not true

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

+ Union $x + $y Union of $x and $y

== Equality $x == $y Returns true if $x and


$y have the same
key/value pairs

=== Identity $x === $y Returns true if $x and


$y have the same
key/value pairs in the
same order and of the
same types

!= Inequality $x != $y Returns true if $x is not


equal to $y

<> Inequality $x <> $y Returns true if $x is not


equal to $y

!== Non-identity $x !== $y Returns true if $x is not


identical to $y

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);

• for - loops through a block of code a specified number of times.


Loop - for statement
for (init; condition; increment)

code to be executed;

24
• foreach - loops through a block of code for each element in an array.
Loop – foreach statement

foreach ($array as $value)

code to be executed;

DAY -6
(06/05/2025)

PHP Functions

The real power of PHP comes from its functions.


PHP has more than 1000 built-in functions, and in addition you can create
your own custom functions.

PHP Built-in Functions


PHP has over 1000 built-in functions that can be called directly, from within a
script, to perform a specific task.

25
function myMessage() {
echo "Hello world!";
}

myMessage();

PHP User Defined Functions


Besides the built-in PHP functions, it is possible to create your own functions.
• A function is a block of statements that can be used repeatedly in a
program.
• A function will not execute automatically when a page loads.
• A function will be executed by a call to the function.
function 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.

Simple Visitor Counter

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)

PHP String Functions

PHP String Functions (Part 1)

strlen(string) - This function counts total no of characters, including numbers


and white spaces in the string

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.

PHP String Functions (Part 2)

strrev(string) -This function is used to reverse the inputed string


strtolower(string) -This function is used to convert all alphabatic characters in
string to thier small/lower case form.
strtoupper(string) -This function is used to convert all alphabatic characters in
string to thier capital/upper case form.
substr_count(string,sub_string,) -This counts the no of substrings matching
the particular value in string. It retuns an integer value.
substr_replace(original_string,string_to_replace) -This function replaces the
cuntent of substring into original string.

DAY -9
(09/05/2025)

File Upload (Part 1)


Setup html form for file uploading

31
Upload file and get file related information like file name, file size, etc
Check for error messages after uploading file

File Upload (Part 2)


Move file from temporary area to user specified location
Restrict uploading to only specific file type
Restrict uploading to a maximum file size

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.

Sending Email (Part 1)


Create HTML form for getting email subject and message from the user
Using the mail() function to send email

Sending Email (Part 2)


Validating whether the name and message have been entered by the user
Check the length of the string using the strlen() function.
Set up the to, subject and message field of the mail() function
Send email and check for any errors

Sending Email (Part 3)


Fix the "Sendmail from not set in php dot ini" error

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)

User Login Part

User Login Part 1


Collecting information from user in a form & connecting to authorized
database.
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

User Login Part 2


retrieves information about inputed username and checks whether given
password matches with the password in database.
mysql_query('TYPE_HERE_YOUR_MYSQL_QUERY') - It is used to run specific
queries on our database.Here it collects information from field username
from specified table.
mysql_num_rows('query') - This function is user to counts no of rows retrieved
from the query given to the database.

34
mysql_fetch_assoc('query')- This function fetches required information from
the database in the form of array.

User Login Part 3


Creating session for holding value and destroying that value by destroying
session.
start_session() - Starts session to hold information from one pages to other
until the session exists.
$_SESSION['variable_name']=value - Stores the value in the session variable.
session_destroy() - destroys the value present in session variable.

DAY -12
(12/05/2025)

User Password Change

User Password Change Part 1


We learn to obtain old existing password and new password from the user.
start_session() - Hold information from previous pages to session page.
$variable_name=$_SESSION['value'] - to retrieve value containing in PHP
variable.
User Password Change Part 2
Checking whether encrypted old password matches with the database
password and new password is same as confirm password.
md5("parameter")- encrypts parameter into irreversible logical code.

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

User Registration Part 1


Creating a form which allows user to input values in page
User Registration Part 2
Striping tags of inputed strings and converting password into md5 encryption.
Use of : strip_tags(strigs) - cuts down unnecessary spaces,html tags and
queries from string.
User Registration Part 3
Checking whether the username and password provided meet the required
length sizes.
Use of : strlen("string") - counts th character length of the string.

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

I) Echo PHP Function, PHP Variables, If and Switch Statements

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.

Ex. The number 11 is an odd number.

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':

echo "$ch is vowel";


break;
case 'o':
case 'O':
echo "$ch is vowel";
break;

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));

echo "2*2 matrix addition is:<br>";

for($i=0;$i<2;$i++)

for($j=0;$j<2;$j++)

echo $one[$i][$j]+$two[$i][$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:

My name is Jai Sharma


My brother's name is Ram Sharma
Note: Use writeName2 function to write the names on screen.

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* :

Total Marks Obtained:


Total Marks:
Percentage:

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);

echo "you had $visitorsnew visitor";

?>

</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 action='string1.php' method='GET'>


22 | P a g
e
<input type='text' name='name'><br><br>

<input type='submit' name='submit'>

</form>

</body>

</html>

<?php

$string=$_GET['name'];

if($string)

echo "input string: ",$string,"<br>";

echo "the number character in the input string : ",strlen($string),"<br>";

echo"Reverse of input string: ",strrev($string),"<br>";

echo"lowercase of input string: ",strtolower($string),"<br>";

echo"uppercase of input string: ",strtoupper($string),"<br>";

$substring='bhonsale';echo"replacing the content of substring with original


string:",substr_replace($string,$substring,4),"<br>";

?>

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>

<form action='upload1.php' method='POST' enctype='multipart/form-data'>


<input type='file' name='file'><p>
<input type='submit' name='submit'>
</form>
</body>
</html>

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>";

echo "temporary strorage folder : ",$store,"<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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy