0% found this document useful (0 votes)
13 views6 pages

WTL Assignment 8

The document outlines an assignment to design a shopping application form using PHP and JavaScript, detailing the purpose, theory, and requirements for implementation. It explains PHP's capabilities, including its data types and array structures, and provides a code example for a shopping cart application that allows users to add items. The conclusion emphasizes PHP's versatility for creating dynamic web pages and its integration with databases through XAMPP.

Uploaded by

kirannandi01234
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)
13 views6 pages

WTL Assignment 8

The document outlines an assignment to design a shopping application form using PHP and JavaScript, detailing the purpose, theory, and requirements for implementation. It explains PHP's capabilities, including its data types and array structures, and provides a code example for a shopping cart application that allows users to add items. The conclusion emphasizes PHP's versatility for creating dynamic web pages and its integration with databases through XAMPP.

Uploaded by

kirannandi01234
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/ 6

Name: Harsh Singh Parihar

Class: CC1 Batch: B


Roll no: 2223337

Assignment No.8

Aim:
Design a shopping application form with following fields [itemID, itemName,
itemQuantity,
Write a PHP script to add and display the items

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:

<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopping Cart</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<style>
body {
font-family: 'Arial', sans-serif;
background-color: #f2f2f2;
padding: 50px;
}

.container {
max-width: 800px;
margin: 0 auto;
background-color: #fff;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

h2 {
text-align: center;
color: #2c3e50;
}

.form-group {
margin-bottom: 20px;
}

.form-group input {
width: 100%;
padding: 12px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 8px;
background-color: #f9f9f9;
}

.form-group input:focus {
border-color: #3498db;
background-color: #fff;
}

button {
padding: 12px 25px;
font-size: 16px;
background-color: #2ecc71;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s;
}

button:hover {
background-color: #27ae60;
}

table {
width: 100%;
margin-top: 30px;
border-collapse: collapse;
text-align: left;
}

table, th, td {
border: 1px solid #ddd;
}

th, td {
padding: 12px;
}

th {
background-color: #3498db;
color: white;
}

td {
background-color: #f9f9f9;
}

.alert {
padding: 10px;
background-color: #e67e22;
color: white;
text-align: center;
border-radius: 5px;
display: none;
}
</style>
</head>
<body>

<div class="container">
<h2>Shopping Cart</h2>
<form method="POST">
<div class="form-group">
<input type="text" name="itemID" placeholder="Enter Item ID" required>
</div>
<div class="form-group">
<input type="text" name="itemName" placeholder="Enter Item Name" required>
</div>
<div class="form-group">
<input type="number" name="itemQuantity" placeholder="Enter Item Quantity"
required>
</div>
<button type="submit" name="addItem">Add Item</button>
</form>

<div class="alert" id="alert">Item added successfully!</div>

<h3>Items in Cart</h3>
<table>
<thead>
<tr>
<th>Item ID</th>
<th>Item Name</th>
<th>Item Quantity</th>
</tr>
</thead>
<tbody>
<?php
session_start();

if (!isset($_SESSION['items'])) {
$_SESSION['items'] = [];
}

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['addItem']))


{
$itemID = htmlspecialchars($_POST['itemID']);
$itemName = htmlspecialchars($_POST['itemName']);
$itemQuantity = htmlspecialchars($_POST['itemQuantity']);
$_SESSION['items'][] = ['itemID' => $itemID, 'itemName' => $itemName,
'itemQuantity' => $itemQuantity];
echo '<script>$("#alert").fadeIn().delay(2000).fadeOut();</script>';
}

foreach ($_SESSION['items'] as $item) {


echo "<tr>
<td>{$item['itemID']}</td>
<td>{$item['itemName']}</td>
<td>{$item['itemQuantity']}</td>
</tr>";
}
?>
</tbody>
</table>
</div>

<script>
$(document).ready(function() {
$("form").on("submit", function() {
$("input[type='text'], input[type='number']").val('');
});
});
</script>

</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