Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What is the code? Use only html, php, and Javacript, to work with the mysql data

ID: 3711509 • Letter: W

Question

What is the code? Use only html, php, and Javacript, to work with the mysql database. You do not need to create the sql database, just make the code work with the sql database explained below.

E-Commerce Site

This site will contain three parts

Part 1

The site will utilize a login, this can be from your previous assignments or you can create a new table for holding usernames and passwords. There will need to be a database storage for the user information. The password should use the hash() function to hash the password. It should direct the user to a page to make a new account on the login page and should not allow for login in the password or username is not correct.

Part 2

There will be a page for looking at the catalogue of items. A new table will be made of all the items to be sold.

Step 1

Enter the MYSQL admin and create a table called products

The table will have

ProductID

Name

Description

Price

Step 2

After you have created the table you will insert these items

Anvil

Axle Grease

Atom Re-Arranger

Bed Springs

Bird Seed

Blasting Powder

Cork

Dsintigration Pistol

Earthquake Pills

Female Roadrunner costume

Giant Rubber Band

Instant Girl

Iron Carrot

Jet Propelled Unicycle

Out-Board Motor

Railroad Track

Rocket Sled

Super Outfit

Time Space Gun

X-Ray

Step 3

Create a catalogue page called catalogue.php and then add the text

“Please select one of our items:” then an options/drop down box

The PHP will call the database and then populate the box with each of the items.

Part 3

Making the shopping cart.

Things the page will need to do-

You will need to use the Session to track the cart products and quantity

You will need to add products to the cart and remove them from the cart

You will need to empty the cart.

You will need to show information in individual products

You will need to display an image of the product when selecting to show info(There are 20, They are JPG files, they are called 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20) example: 1.jpg

You will need to show a total cost of all the products in the cart

This page can be the same page as catalogue.php.

Anvil

Axle Grease

Atom Re-Arranger

Bed Springs

Bird Seed

Blasting Powder

Cork

Dsintigration Pistol

Earthquake Pills

Female Roadrunner costume

Giant Rubber Band

Instant Girl

Iron Carrot

Jet Propelled Unicycle

Out-Board Motor

Railroad Track

Rocket Sled

Super Outfit

Time Space Gun

X-Ray

Explanation / Answer

ShoppingCart.php

<?php session_start();
class ShoppingCart {
protected $crtContnt = array();
  
public function __construct(){
$this->crtContnt = !empty($_SESSION['crtContnt'])?$_SESSION['crtContnt']:NULL;
if ($this->crtContnt === NULL){
$this->crtContnt = array('ttl' => 0, 'ttlItems' => 0);
}
}
  
public function cont(){
$crt = array_reverse($this->crtContnt);

unset($crt['ttlItems']);
unset($crt['ttl']);

return $crt;
}

public function getItm($IDrow){
return (in_array($IDrow, array('ttlItems', 'ttl'), TRUE) OR ! isset($this->crtContnt[$IDrow]))
? FALSE
: $this->crtContnt[$IDrow];
}

public function ttlItems(){
return $this->crtContnt['ttlItems'];
}
  
  
public function ttl(){
return $this->crtContnt['ttl'];
}
  
  
public function itemInsert($product = array()){
if(!is_array($product) OR count($product) === 0){
return FALSE;
}else{
if(!isset($product['pid'], $product['pname'], $product['pprice'], $product['pqty'])){
return FALSE;
}else{

$product['pqty'] = (float) $product['pqty'];
if($product['pqty'] == 0){
return FALSE;
}
  
$product['pprice'] = (float) $product['pprice'];
$rowid = md5($product['pid']);
$OldQty = isset($this->crtContnt[$rowid]['pqty']) ? (int) $this->crtContnt[$rowid]['pqty'] : 0;
$product['rowid'] = $rowid;
$product['pqty'] += $OldQty;
$this->crtContnt[$rowid] = $product;
  
if($this->sveCrt()){
return isset($rowid) ? $rowid : TRUE;
}else{
return FALSE;
}
}
}
}

public function up($product = array()){
if (!is_array($product) OR count($product) === 0){
return FALSE;
}else{
if (!isset($product['rowid'], $this->crtContnt[$product['rowid']])){
return FALSE;
}else{
if(isset($product['pqty'])){
$product['pqty'] = (float) $product['pqty'];
if ($product['pqty'] == 0){
unset($this->crtContnt[$product['rowid']]);
return TRUE;
}
}
  
$unique = array_intersect(array_keys($this->crtContnt[$product['rowid']]), array_keys($product));
if(isset($product['pprice'])){
$product['pprice'] = (float) $product['pprice'];
}
foreach(array_diff($unique, array('pid', 'pname')) as $unique){
$this->crtContnt[$product['rowid']][$key] = $product[$key];
}
$this->sveCrt();
return TRUE;
}
}
}
  

protected function sveCrt(){
$this->crtContnt['ttlItems'] = $this->crtContnt['ttl'] = 0;
foreach ($this->crtContnt as $unique => $values){
if(!is_array($val) OR !isset($val['pprice'], $values['pqty'])){
continue;
}

$this->crtContnt['ttl'] += ($val['pprice'] * $values['pqty']);
$this->crtContnt['ttlItems'] += $values['pqty'];
$this->crtContnt[$key]['subtotal'] = ($this->crtContnt[$key]['pprice'] * $this->crtContnt[$key]['pqty']);
}
  
if(count($this->crtContnt) <= 2){
unset($_SESSION['crtContnt']);
return FALSE;
}else{
$_SESSION['crtContnt'] = $this->crtContnt;
return TRUE;
}
}
  
public function rm($IDrow){
// unset & save
unset($this->crtContnt[$IDrow]);
$this->sveCrt();
return TRUE;
}
  
public function delete(){
$this->crtContnt = array('ttl' => 0, 'ttlItems' => 0);
unset($_SESSION['crtContnt']);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote