0% found this document useful (0 votes)
4 views

WTL_Assignment_9[2][1]

The document outlines an assignment to create a database table for student records using PHP, focusing on data types and arrays in PHP. It explains PHP's capabilities as a server-side scripting language and its integration with databases like MySQL through XAMPP. The document also includes a sample HTML form and PHP code for displaying student records based on user input for passing year and class grades.

Uploaded by

kirannandi01234
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

WTL_Assignment_9[2][1]

The document outlines an assignment to create a database table for student records using PHP, focusing on data types and arrays in PHP. It explains PHP's capabilities as a server-side scripting language and its integration with databases like MySQL through XAMPP. The document also includes a sample HTML form and PHP code for displaying student records based on user input for passing year and class grades.

Uploaded by

kirannandi01234
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Name: Harsh Singh Parihar

Class: CC1 Batch: B


Roll no: 2223337

Assignment No.9

Aim:
Create the database table with the entries mentioned:
[rollNo, studName, studDept, passingYear, classGrades] Grades should be either {First
Class, Second Class, Pass}
Design the UI as given below and show the appropriate result through PHP script

Objective: To learn about concept and implementation of JAVASCRIPT

Theory:

PHP stands for Hypertext Preprocessor. PHP is a very popular and widely-used open source
server-side scripting language to write dynamically generated web pages. PHP was originally
created by Rasmus Lerdorf in 1994. It was initially known as Personal Home Page.

PHP scripts are executed on the server and the result is sent to the web browser as plain
HTML.
PHP can be integrated with the number of popular databases, including MySQL,
PostgreSQL,
Oracle, Microsoft SQL Server, Sybase, and so on

Data Types in PHP

The values assigned to a PHP variable may be of different data types including simple string
and numeric types to more complex data types like arrays and objects.
PHP supports a total eight primitive data types: Integer, Floating point number or Float,
String, Booleans, Array, Object, resource and NULL. These data types are used to construct
variables. Now let's discuss each one of them in detail.

What is PHP Arrays?

Arrays are complex variables that allow us to store more than one value or a group of values
under a single variable name.
Types of Arrays in PHP

There are three types of arrays that you can create. These are:
Indexed array/ Numeric array — An array with a numeric key.
Associative array — An array where each key has its own specific value.
Multidimensional array — An array containing one or more arrays within itself.

PHP Database connection

Requirements: XAMPP web server procedure:


Start XAMPP server by starting Apache and MySQL.
Write PHP script for connecting to XAMPP.
Run it in the local browser.
Database is successfully created which is based on the PHP code.
In PHP, we can connect to the database using XAMPP web server by using the following
path. "localhost/phpmyadmin"

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Student Records</title>
</head>
<body>

<form action="" method="post">


<label for="year">Years:</label>
<select name="year" id="year">
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
</select>

<br><br>

<input type="radio" name="classGrade" value="First Class"> First Class<br>


<input type="radio" name="classGrade" value="Second Class"> Second Class<br>
<input type="radio" name="classGrade" value="All" checked> All<br>

<br>

<button type="submit" name="display">Display</button>


</form>

<?php
if (isset($_POST['display'])) {
$conn = new mysqli("localhost", "username", "password", "database_name");

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$year = $_POST['year'];
$classGrade = $_POST['classGrade'];

if ($classGrade == "All") {
$sql = "SELECT * FROM students WHERE passingYear = ?";
} else {
$sql = "SELECT * FROM students WHERE passingYear = ? AND classGrades = ?";
}

$stmt = $conn->prepare($sql);
if ($classGrade == "All") {
$stmt->bind_param("i", $year);
} else {
$stmt->bind_param("is", $year, $classGrade);
}

$stmt->execute();
$result = $stmt->get_result();

if ($result->num_rows > 0) {
echo "<table border='1'>";
echo "<tr><th>Roll
No</th><th>Name</th><th>Department</th><th>Year</th><th>Class</th></tr>";
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["rollNo"] . "</td><td>" . $row["studName"] . "</td><td>"
. $row["studDept"] . "</td><td>" . $row["passingYear"] . "</td><td>" . $row["classGrades"]
. "</td></tr>";
}
echo "</table>";
} else {
echo "No results found.";
}

$stmt->close();
$conn->close();
}
?>

</body>
</html>

Output:
Conclusion:

PHP is a powerful, open-source server-side scripting language, and initially known as


Personal Home Page. It is widely used for creating dynamic web pages and can interact with
various popular databases like MySQL, PostgreSQL, and Oracle. PHP supports several data
types, including integers, floats, strings, booleans, arrays, objects, resources, and NULL.
Arrays in PHP come in three types: indexed, associative, and multidimensional, allowing
storage of complex data structures within a single variable. To work with databases locally,
PHP can connect via XAMPP, where the Apache and MySQL servers are managed to allow
testing and development through "localhost/phpmyadmin." This setup makes PHP a flexible
tool for building data-driven applications.

You might also like