php getdbused,PHP之购物车

该文章记录了购物车的实现代码,仅供参考

book_sc_fns.php

include_once('output_fns.php');

include_once('book_fns.php');

include_once('db_fns.php');

include_once("user_auth_fns.php");

include_once("admin_fns.php");

include_once("data_valid_fns.php");

include_once("order_fns.php");

?>

output_fns.php

function do_html_header($title = '') {

// print an HTML header

// declare the session variables we want access to inside the function

if (!$_SESSION['items']) {

$_SESSION['items'] = '0';

}

if (!$_SESSION['total_price']) {

$_SESSION['total_price'] = '0.00';

}

?>

<?php echo $title; ?>

h2 { font-family: Arial, Helvetica, sans-serif; font-size: 22px; color: red; margin: 6px }

body { font-family: Arial, Helvetica, sans-serif; font-size: 13px }

li, td { font-family: Arial, Helvetica, sans-serif; font-size: 13px }

hr { color: #FF0000; width=70%; text-align=center}

a { color: #000000 }

Bookorama

align="left" valign="bottom" height="55" width="325"/>

if(isset($_SESSION['admin_user'])) {

echo " ";

} else {

echo "Total Items = ".$_SESSION['items'];

}

?>

if(isset($_SESSION['admin_user'])) {

display_button('logout.php', 'log-out', 'Log Out');

} else {

display_button('show_cart.php', 'view-cart', 'View Your Shopping Cart');

}

?>

if(isset($_SESSION['admin_user'])) {

echo " ";

} else {

echo "Total Price = $".number_format($_SESSION['total_price'],2);

}

?>

if($title) {

do_html_heading($title);

}

}

function do_html_footer() {

// print an HTML footer

?>

}

function do_html_heading($heading) {

// print heading

?>

<?php echo $heading; ?>

}

function do_html_URL($url, $name) {

// output URL as link and br

?>

<?php echo $name; ?>

}

function display_categories($cat_array) {

if (!is_array($cat_array)) {

echo "

No categories currently available

";

return;

}

echo "

  • ";

foreach ($cat_array as $row) {

$url = "show_cat.php?catid=".$row['catid'];

$title = $row['catname'];

echo "

";

do_html_url($url, $title);

echo "

";

}

echo "

";

echo "


";

}

function display_books($book_array) {

//display all books in the array passed in

if (!is_array($book_array)) {

echo "

No books currently available in this category

";

} else {

//create table

echo "

//create a table row for each book

foreach ($book_array as $row) {

$url = "show_book.php?isbn=".$row['isbn'];

echo "

";

if (@file_exists("images/".$row['isbn'].".jpg")) {

$title = "p

style=\"border: 1px solid black\"/>";

do_html_url($url, $title);

} else {

echo " ";

}

echo "

";

$title = $row['title']." by ".$row['author'];

do_html_url($url, $title);

echo "

";

}

echo "

";

}

echo "


";

}

function display_book_details($book) {

// display all details about this book

if (is_array($book)) {

echo "

//display the picture if there is one

if (@file_exists("images/".$book['isbn'].".jpg")) {

$size = GetImageSize("images/".$book['isbn'].".jpg");

if(($size[0] > 0) && ($size[1] > 0)) {

echo "

p

style=\"border: 1px solid black\"/>

";

}

}

echo "

  • ";

echo "

Author: ";

echo $book['author'];

echo "

ISBN: ";

echo $book['isbn'];

echo "

Our Price: ";

echo number_format($book['price'], 2);

echo "

Description: ";

echo $book['description'];

echo "

";

} else {

echo "

The details of this book cannot be displayed at this time.

";

}

echo "


";

}

function display_checkout_form() {

//display the form that asks for name and address

?>

Your Details
Name
Address
City/Suburb
State/Province
Postal Code or Zip Code
Country
Shipping Address (leave blank if as above)
Name
Address
City/Suburb
State/Province
Postal Code or Zip Code
Country

Please press Purchase to confirm

your purchase, or Continue Shopping to add or remove items.


}

function display_shipping($shipping) {

// display table row with shipping cost and total price including shipping

?>

Shipping <?php echo number_format($shipping, 2); ?>
TOTAL INCLUDING SHIPPING$ <?php echo number_format($shipping+$_SESSION['total_price'], 2); ?>

}

function display_card_form($name) {

//display form asking for credit card details

?>

Credit Card Details
Type

VISA

MasterCard

American Express

Number
AMEX code (if required)
Expiry DateMonth

01

02

03

04

05

06

07

08

09

10

11

12

Year

for ($y = date("Y"); $y < date("Y") + 10; $y++) {

echo "".$y."";

}

?>

Name on Card

Please press Purchase to confirm your purchase, or Continue Shopping to

add or remove items

}

function display_cart($cart, $change = true, $images = 1) {

// display items in shopping cart

// optionally allow changes (true or false)

// optionally include images (1 - yes, 0 - no)

echo "

ItemPriceQuantityTotal

//display each item as a table row

foreach ($cart as $isbn => $qty) {

$book = get_book_details($isbn);

echo "

";

if($images == true) {

echo "

";

if (file_exists("images/".$isbn.".jpg")) {

$size = GetImageSize("images/".$isbn.".jpg");

if(($size[0] > 0) && ($size[1] > 0)) {

echo "p

style=\"border: 1px solid black\"

width=\"".($size[0]/3)."\"

height=\"".($size[1]/3)."\"/>";

}

} else {

echo " ";

}

echo "

";

}

echo "

".$book['title']."

by ".$book['author']."

\$".number_format($book['price'], 2)."";

// if we allow changes, quantities are in text boxes

if ($change == true) {

echo "";

} else {

echo $qty;

}

echo "

\$".number_format($book['price']*$qty,2)."\n";

}

// display total row

echo "

 ".$_SESSION['items']."

\$".number_format($_SESSION['total_price'], 2)."

";

// display save change button

if($change == true) {

echo "

 

border=\"0\" alt=\"Save Changes\"/>

 ";

}

echo "

";

}

function display_login_form() {

// dispaly form asking for name and password

?>

Username:
Password:

}

function display_admin_menu() {

?>

Go to main site

Add a new category

Add a new book

Change admin password

}

function display_button($target, $image, $alt) {

echo "

p

alt=\"".$alt."\" border=\"0\" height=\"50\"

width=\"135\"/>

";

}

function display_form_button($image, $alt) {

echo "

src=\"images/".$image.".gif\"

alt=\"".$alt."\" border=\"0\" height=\"50\"

width=\"135\"/>

";

}

?>

book_fns.php

function get_categories() {

$conn = db_connect();

$query = "select catid, catname from categories";

$result = @$conn -> query($query);

if (!$result) {

return false;

}

$num_cats = @$result -> num_rows;

if ($num_cats == 0) {

return false;

}

$result = db_result_to_array($result);

return $result;

}

function get_category_name($catid) {

$conn = db_connect();

$query = "select catname from categories where catid = ".$catid."";

$result = @$conn -> query($query);

if (!$result) {

return false;

}

$num_cats = @$result -> num_rows;

if ($num_cats == 0) {

return false;

}

$row = $result -> fetch_object();

return $row -> catname;

}

function get_books($catid) {

$conn = db_connect();

$query = "select * from books where catid = ".$catid."";

$result = @$conn -> query($query);

if (!$result) {

return false;

}

$num_cats = @$result -> num_rows;

if ($num_cats == 0) {

return false;

}

$result = db_result_to_array($result);

return $result;

}

function get_book_details($isbn) {

if ((!$isbn) || $isbn == '') {

return false;

}

$conn = db_connect();

$query = "select * from books where isbn = ".$isbn."";

$result = @$conn -> query($query);

if (!$result) {

return false;

}

$row = @$result -> fetch_assoc();

return $row;

}

function calculate_price($cart) {

$price = 0;

if (is_array($cart)) {

$conn = db_connect();

foreach ($cart as $isbn => $qty) {

$query = "select price from books where isbn='".$isbn."'";

$result = $conn -> query($query);

if ($result) {

$items = $result -> fetch_object();

$item_price = $items -> price;

$price += $item_price * $qty;

}

}

}

return $price;

}

function calculate_items($cart) {

$items = 0;

if (is_array($cart)) {

$conn = db_connect();

foreach ($cart as $isbn => $qty) {

$items += $qty;

}

}

return $items;

}

function calculate_shipping_cost() {

return 20.00;

}

?>

db_fns.php

function db_connect() {

$result = new mysqli('127.0.0.1', 'book_sc', 'password', 'book_sc');

if (!$result) {

return false;

}

$result->autocommit(TRUE);

return $result;

}

function db_result_to_array($result) {

$res_array = array();

for ($count=0; $row = $result->fetch_assoc(); $count++) {

$res_array[$count] = $row;

}

return $res_array;

}

?>

user_auth_fns.php

require_once('db_fns.php');

function login($username, $password) {

// check username and password with db

// if yes, return true

// else return false

// connect to db

$conn = db_connect();

if (!$conn) {

return 0;

}

// check if username is unique

$result = $conn->query("select * from admin

where username='".$username."'

and password = sha1('".$password."')");

if (!$result) {

return 0;

}

if ($result->num_rows>0) {

return 1;

} else {

return 0;

}

}

function check_admin_user() {

// see if somebody is logged in and notify them if not

if (isset($_SESSION['admin_user'])) {

return true;

} else {

return false;

}

}

function change_password($username, $old_password, $new_password) {

// change password for username/old_password to new_password

// return true or false

// if the old password is right

// change their password to new_password and return true

// else return false

if (login($username, $old_password)) {

if (!($conn = db_connect())) {

return false;

}

$result = $conn->query("update admin

set password = sha1('".$new_password."')

where username = '".$username."'");

if (!$result) {

return false; // not changed

} else {

return true; // changed successfully

}

} else {

return false; // old password was wrong

}

}

?>

admin_fns.php

// This file contains functions used by the admin interface

// for the Book-O-Rama shopping cart.

function display_category_form($category = '') {

// This displays the category form.

// This form can be used for inserting or editing categories.

// To insert, don't pass any parameters. This will set $edit

// to false, and the form will go to insert_category.php.

// To update, pass an array containing a category. The

// form will contain the old data and point to update_category.php.

// It will also add a "Delete category" button.

// if passed an existing category, proceed in "edit mode"

$edit = is_array($category);

// most of the form is in plain HTML with some

// optional PHP bits throughout

?>

action="<?php echo $edit ? 'edit_category.php' : 'insert_category.php'; ?>">

Category Name:

value="<?php echo $edit ? $category['catname'] : ''; ?>" />

align="center">

if ($edit) {

echo "";

}

?>

value="<?php echo $edit ? 'Update' : 'Add'; ?> Category" />

if ($edit) {

//allow deletion of existing categories

echo "

";

}

?>

}

function display_book_form($book = '') {

// This displays the book form.

// It is very similar to the category form.

// This form can be used for inserting or editing books.

// To insert, don't pass any parameters. This will set $edit

// to false, and the form will go to insert_book.php.

// To update, pass an array containing a book. The

// form will be displayed with the old data and point to update_book.php.

// It will also add a "Delete book" button.

// if passed an existing book, proceed in "edit mode"

$edit = is_array($book);

// most of the form is in plain HTML with some

// optional PHP bits throughout

?>

action="<?php echo $edit ? 'edit_book.php' : 'insert_book.php';?>">

ISBN:

value="<?php echo $edit ? $book['isbn'] : ''; ?>" />

Book Title:

value="<?php echo $edit ? $book['title'] : ''; ?>" />

Book Author:

value="<?php echo $edit ? $book['author'] : ''; ?>" />

Category:

// list of possible categories comes from database

$cat_array=get_categories();

foreach ($cat_array as $thiscat) {

echo "

// if existing book, put in current catgory

if (($edit) && ($thiscat['catid'] == $book['catid'])) {

echo " selected";

}

echo ">".$thiscat['catname']."

";

}

?>

Price:

value="<?php echo $edit ? $book['price'] : ''; ?>" />

Description:

name="description"><?php echo $edit ? $book['description'] : ''; ?>

align="center">

if ($edit)

// we need the old isbn to find book in database

// if the isbn is being updated

echo "

value=\"".$book['isbn']."\" />";

?>

value="<?php echo $edit ? 'Update' : 'Add'; ?> Book" />

if ($edit) {

echo "

value=\"".$book['isbn']."\" />

";

}

?>

}

function display_password_form() {

// displays html change password form

?>

Old password:
New password:
Repeat new password:

}

function insert_category($catname) {

// inserts a new category into the database

$conn = db_connect();

// check category does not already exist

$query = "select *

from categories

where catname='".$catname."'";

$result = $conn->query($query);

if ((!$result) || ($result->num_rows!=0)) {

return false;

}

// insert new category

$query = "insert into categories values

(0, '".$catname."')";

$result = $conn->query($query);

if (!$result) {

return false;

} else {

return true;

}

}

function insert_book($isbn, $title, $author, $catid, $price, $description) {

// insert a new book into the database

$conn = db_connect();

// check book does not already exist

$query = "select *

from books

where isbn='".$isbn."'";

$result = $conn->query($query);

if ((!$result) || ($result->num_rows!=0)) {

return false;

}

// insert new book

$query = "insert into books values

('".$isbn."', '".$author."', '".$title."',

'".$catid."', '".$price."', '".$description."')";

$result = $conn->query($query);

if (!$result) {

return false;

} else {

return true;

}

}

function update_category($catid, $catname) {

// change the name of category with catid in the database

$conn = db_connect();

$query = "update categories

set catname='".$catname."'

where catid='".$catid."'";

$result = @$conn->query($query);

if (!$result) {

return false;

} else {

return true;

}

}

function update_book($oldisbn, $isbn, $title, $author, $catid,

$price, $description) {

// change details of book stored under $oldisbn in

// the database to new details in arguments

$conn = db_connect();

$query = "update books

set isbn= '".$isbn."',

title = '".$title."',

author = '".$author."',

catid = '".$catid."',

price = '".$price."',

description = '".$description."'

where isbn = '".$oldisbn."'";

$result = @$conn->query($query);

if (!$result) {

return false;

} else {

return true;

}

}

function delete_category($catid) {

// Remove the category identified by catid from the db

// If there are books in the category, it will not

// be removed and the function will return false.

$conn = db_connect();

// check if there are any books in category

// to avoid deletion anomalies

$query = "select *

from books

where catid=".$catid."";

$result = @$conn->query($query);

if ((!$result) || (@$result->num_rows > 0)) {

return false;

}

$query = "delete from categories

where catid='".$catid."'";

$result = @$conn->query($query);

if (!$result) {

return false;

} else {

return true;

}

}

function delete_book($isbn) {

// Deletes the book identified by $isbn from the database.

$conn = db_connect();

$query = "delete from books

where isbn='".$isbn."'";

$result = @$conn->query($query);

if (!$result) {

return false;

} else {

return true;

}

}

?>

data_valid_fns.php

function filled_out($form_vars) {

// test that each variable has a value

foreach ($form_vars as $key => $value) {

if ((!isset($key)) || ($value == '')) {

return false;

}

}

return true;

}

function valid_email($address) {

// check an email address is possibly valid

if (ereg("^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$", $address)) {

return true;

} else {

return false;

}

}

?>

order_fns.php

function process_card($card_details) {

// connect to payment gateway or

// use gpg to encrypt and mail or

// store in DB if you really want to

return true;

}

function insert_order($order_details) {

// extract order_details out as variables

extract($order_details);

// set shipping address same as address

if((!$ship_name) && (!$ship_address) && (!$ship_city) && (!$ship_state) && (!$ship_zip) && (!$ship_country)) {

$ship_name = $name;

$ship_address = $address;

$ship_city = $city;

$ship_state = $state;

$ship_zip = $zip;

$ship_country = $country;

}

$conn = db_connect();

// we want to insert the order as a transaction

// start one by turning off autocommit

$conn->autocommit(FALSE);

// insert customer address

$query = "select customerid from customers where

name = '".$name."' and address = '".$address."'

and city = '".$city."' and state = '".$state."'

and zip = '".$zip."' and country = '".$country."'";

$result = $conn->query($query);

if($result->num_rows>0) {

$customer = $result->fetch_object();

$customerid = $customer->customerid;

} else {

$query = "insert into customers values

(0, '".$name."','".$address."','".$city."','".$state."','".$zip."','".$country."')";

$result = $conn->query($query);

if (!$result) {

return false;

}

}

$customerid = $conn->insert_id;

$date = date("Y-m-d");

$query = "insert into orders values

(0, '".$customerid."', '".$_SESSION['total_price']."', '".$date."', '".'PARTIAL'."',

'".$ship_name."', '".$ship_address."', '".$ship_city."', '".$ship_state."',

'".$ship_zip."', '".$ship_country."')";

$result = $conn->query($query);

if (!$result) {

return false;

}

$query = "select orderid from orders where

customerid = '".$customerid."' and

amount > (".$_SESSION['total_price']."-.001) and

amount < (".$_SESSION['total_price']."+.001) and

date = '".$date."' and

order_status = 'PARTIAL' and

ship_name = '".$ship_name."' and

ship_address = '".$ship_address."' and

ship_city = '".$ship_city."' and

ship_state = '".$ship_state."' and

ship_zip = '".$ship_zip."' and

ship_country = '".$ship_country."'";

$result = $conn->query($query);

if($result->num_rows>0) {

$order = $result->fetch_object();

$orderid = $order->orderid;

} else {

return false;

}

// insert each book

foreach($_SESSION['cart'] as $isbn => $quantity) {

$detail = get_book_details($isbn);

$query = "delete from order_items where

orderid = '".$orderid."' and isbn = '".$isbn."'";

$result = $conn->query($query);

$query = "insert into order_items values

('".$orderid."', '".$isbn."', ".$detail['price'].", $quantity)";

$result = $conn->query($query);

if(!$result) {

return false;

}

}

// end transaction

$conn->commit();

$conn->autocommit(TRUE);

return $orderid;

}

?>

index.php

require_once("book_sc_fns.php");

// The shopping cart needs sessions, so start one

session_start();

// Display header

do_html_header("Book-store");

// Show cat title

echo "

Please chose a category:

";

$cat_array = get_categories();

display_categories($cat_array);

// If login as admin, show add, delete, edit cat link

if (isset($_SESSION['admin_user'])) {

display_button("admin.php", "admin-menu", "Admin Menu");

}

do_html_footer();

?>

login.php

require_once("book_sc_fns.php");

do_html_header("Administration");

display_login_form();

do_html_footer();

?>

logout.php

// include function files for this application

require_once('book_sc_fns.php');

session_start();

$old_user = $_SESSION['admin_user']; // store to test if they *were* logged in

unset($_SESSION['admin_user']);

session_destroy();

// start output html

do_html_header("Logging Out");

if (!empty($old_user)) {

echo "

Logged out.

";

do_html_url("login.php", "Login");

} else {

// if they weren't logged in but came to this page somehow

echo "

You were not logged in, and so have not been logged out.

";

do_html_url("login.php", "Login");

}

do_html_footer();

?>

admin.php

require_once("book_sc_fns.php");

session_start();

if ($_POST["username"] && $_POST["passwd"]) {

$username = $_POST["username"];

$passwd = $_POST["passwd"];

if (login($username, $passwd)) {

$_SESSION["admin_user"] = $username;

}else {

do_html_header("Problem:");

echo "

You could not be logged in.

You must be logged in to view this page.

";

do_html_url("login.php", "Login");

do_html_footer();

exit;

}

}

do_html_header("Administrtion");

if (check_admin_user()) {

display_admin_menu();

}else {

echo "

You are not authorized to enter the administration area.

";

}

do_html_footer();

?>

insert_book_form.php

require_once("book_sc_fns.php");

session_start();

do_html_header("Add a category");

if (check_admin_user()) {

display_book_form();

do_html_url("admin.php", "Back to administration menu");

}else {

echo "

You are not authorized to enter the administration area.

";

}

do_html_footer();

?>

insert_book.php

require_once("book_sc_fns.php");

session_start();

do_html_header("Adding a book");

if (check_admin_user()) {

if (filled_out($_POST)) {

$isbn = $_POST['isbn'];

$title = $_POST['title'];

$author = $_POST['author'];

$catid = $_POST['catid'];

$price = $_POST['price'];

$description = $_POST['description'];

if (insert_book($isbn, $title, $author, $catid, $price, $description)) {

echo "

Book ".stripslashes($title)." was added to the database.

";

}else {

echo "

Book ".stripslashes($title)." could not be added to the database.

";

}

}else {

echo "

You have not filled out the form. Please try again

";

}

}else {

echo "

You are not authorized to enter the administration area.

";

}

do_html_footer();

?>

insert_category_form.php

require_once("book_sc_fns.php");

session_start();

do_html_header("Add a category");

if (check_admin_user()) {

display_category_form();

do_html_url("admin.php", "Back to administration menu");

}else {

echo "

You are not authorized to enter the administration area.

";

}

do_html_footer();

?>

insert_category.php

require_once("book_sc_fns.php");

session_start();

do_html_header("Adding a category");

if (check_admin_user()) {

if (filled_out($_POST)) {

$catname = $_POST['catname'];

if (insert_category($catname)) {

echo "

Category \"".$catname."\" was added to the database.

";

}else {

echo "

Category \"".$catname."\" could not be added to the database.

";

}

}else {

echo "

You have not filled out the form. Please try again

";

}

}else {

echo "

You are not authorized to enter the administration area.

";

}

do_html_footer();

?>

delete_book.php

require_once("book_sc_fns.php");

session_start();

do_html_header("Deleting book");

if (check_admin_user()) {

if (isset($_POST['isbn'])) {

if (delete_book($_POST['isbn'])) {

echo "

Book was deleted.

";

}else {

echo "

Book could not be deleted.

";

}

}else {

echo "

No Book specified. Please try again

";

}

do_html_url("admin.php", "Back to administation menu");

}else {

echo "

You are not authorized to enter the administration area.

";

}

do_html_footer();

?>

delete_category.php

require_once("book_sc_fns.php");

session_start();

do_html_header("Deleting category");

if (check_admin_user()) {

if (isset($_POST['catid'])) {

if (delete_category($_POST['catid'])) {

echo "

Category was deleted.

";

}else {

echo "

Category could not be deleted.

";

}

}else {

echo "

No category specified. Please try again

";

}

do_html_url("admin.php", "Back to administation menu");

}else {

echo "

You are not authorized to enter the administration area.

";

}

do_html_footer();

?>

edit_book_form.php

require_once("book_sc_fns.php");

session_start();

do_html_header("Edit book details");

if (check_admin_user()) {

if ($book = get_book_details($_GET['isbn'])) {

display_book_form($book);

}else {

echo "

Could not retrieve book details.

";

}

do_html_url("admin.php", "Back to administration menu");

}else {

echo "

You are not authorized to enter the administration area.

";

}

do_html_footer();

?>

edit_book.php

require_once("book_sc_fns.php");

session_start();

do_html_header("Updating book");

if (check_admin_user()) {

if (filled_out($_POST)) {

$old_isbn = $_POST['oldisbn'];

$isbn = $_POST['isbn'];

$title = $_POST['title'];

$author = $_POST['author'];

$catid = $_POST['catid'];

$price = $_POST['price'];

$description = $_POST['description'];

if (update_book($old_isbn, $isbn, $title, $author, $catid, $price, $description)) {

echo "

Book was updated.

";

}else {

echo "

Book could not be updated.

";

}

}else {

echo "

You have not filled out the form. Please try again

";

}

do_html_url("admin.php", "Back to administation menu");

}else {

echo "

You are not authorized to enter the administration area.

";

}

do_html_footer();

?>

edit_category_form.php

require_once("book_sc_fns.php");

session_start();

do_html_header("Edit category");

if (check_admin_user()) {

if ($catname = get_category_name($_GET['catid'])) {

$catid = $_GET['catid'];

$cat = compact('catname', 'catid');

display_category_form($cat);

}else {

echo "

Could not retrieve catogory details.

";

}

do_html_url("admin.php", "Back to administration menu");

}else {

echo "

You are not authorized to enter the administration area.

";

}

do_html_footer();

?>

edit_category.php

require_once("book_sc_fns.php");

session_start();

do_html_header("Updating category");

if (check_admin_user()) {

if (filled_out($_POST)) {

if (update_category($_POST['catid'], $_POST['catname'])) {

echo "

Category was updated.

";

}else {

echo "

Category could not be updated.

";

}

}else {

echo "

You have not filled out the form. Please try again

";

}

do_html_url("admin.php", "Back to administation menu");

}else {

echo "

You are not authorized to enter the administration area.

";

}

do_html_footer();

?>

change_password_form.php

require_once('book_sc_fns.php');

session_start();

do_html_header("Change administrator password");

check_admin_user();

display_password_form();

do_html_url("admin.php", "Back to administration menu");

do_html_footer();

?>

change_password.php

require_once('book_sc_fns.php');

session_start();

do_html_header('Changing password');

check_admin_user();

if (!filled_out($_POST)) {

echo "

You have not filled out the form completely.

Please try again.

";

do_html_url("admin.php", "Back to administration menu");

do_html_footer();

exit;

} else {

$new_passwd = $_POST['new_passwd'];

$new_passwd2 = $_POST['new_passwd2'];

$old_passwd = $_POST['old_passwd'];

if ($new_passwd != $new_passwd2) {

echo "

Passwords entered were not the same. Not changed.

";

} else if ((strlen($new_passwd)>16) || (strlen($new_passwd)<6)) {

echo "

New password must be between 6 and 16 characters. Try again.

";

} else {

// attempt update

if (change_password($_SESSION['admin_user'], $old_passwd, $new_passwd)) {

echo "

Password changed.

";

} else {

echo "

Password could not be changed.

";

}

}

}

do_html_url("admin.php", "Back to administration menu");

do_html_footer();

?>

checkout.php

include("book_sc_fns.php");

session_start();

do_html_header("Checkout");

if (($_SESSION['cart']) && (array_count_values($_SESSION['cart']))) {

display_cart($_SESSION['cart'], false, 0);

display_checkout_form();

}else {

echo "

There are no items in your cart

";

}

display_button("show_cart.php", "continue-shopping", "Continue Shopping");

do_html_footer();

?>

process.php

include("book_sc_fns.php");

session_start();

do_html_header("Checkout");

$card_type = $_POST['card_type'];

$card_number = $_POST['card_number'];

$card_month = $_POST['card_month'];

$card_year = $_POST['card_year'];

$card_name = $_POST['card_name'];

if ($_SESSION["cart"] && ($card_type) && ($card_number)

&& ($card_month) && ($card_year) && ($card_name)) {

display_cart($_SESSION['cart'], false, 0);

display_shipping(calculate_shipping_cost());

if (process_card($_POST)) {

session_destroy();

echo "

Thank you for shopping with us.Your order has been placed.

";

display_button("index.php", "continue-shopping", "Continue Shopping");

}else {

echo "

Could not process your card.Please contact the card issuer or try again.

";

display_button("purchase.php", "back", "Back");

}

}else {

echo "

You did not fill in all the fields, please try again.


";

display_button("purchase.php", "back", "Back");

}

do_html_footer();

?>

purchase.php

include("book_sc_fns.php");

session_start();

do_html_header("Checkout");

// Info

$name = $_POST['name'];

$address = $_POST['address'];

$city = $_POST['city'];

$zip = $_POST['zip'];

$country = $_POST['country'];

// Check if filled out

if (($_SESSION['cart']) && ($name) && ($address) && ($city) && ($zip) && ($country)) {

if ((insert_order($_POST)) != false) {

display_cart($_SESSION['cart'], false, 0);

display_shipping(calculate_shipping_cost());

display_card_form($name);

display_button('show_cart.php', 'continue-shopping', 'Continu Shopping');

}else {

echo "

Could not store data, please try again.


";

display_button('checkout.php', 'back', 'back');

}

}else {

echo "

You did not fill in all the fields, please try again.


";

display_button('checkout.php', 'back', 'back');

}

do_html_footer();

?>

show_book.php

// include function files for this application

require_once('book_sc_fns.php');

session_start();

$isbn = $_GET['isbn'];

$book = get_book_details($isbn);

do_html_header($book['title']);

display_book_details($book);

$target = "index.php";

if ($book['catid']) {

$target = "show_cat.php?catid=".$book['catid']."";

}

if (check_admin_user()) {

display_button("edit_book_form.php?isbn=".$isbn."", "edit-item", "Edit Book");

display_button("admin.php", "admin-menu", "Admin Menu");

display_button($target, "continue", "Continue");

}else {

display_button("show_cart.php?new=".$isbn."", "add-to-cart", "Add ".$book['title']." To My Shopping Cart");

display_button($target, "continue-shopping", "Continue Shopping");

}

do_html_footer();

?>

show_cart.php

include("book_sc_fns.php");

session_start();

@$new = $_GET['new'];

if ($new) {

// If cart is null create a new cat

if (!isset($_SESSION['cart'])) {

$_SESSION['cart'] = array();

$_SESSION['item'] = 0;

$_SESSION['total_price'] = '0.00';

}

// book count

if (isset($_SESSION['cart'][$new])) {

$_SESSION['cart'][$new] ++;

}else {

$_SESSION['cart'][$new] = 1;

}

$_SESSION['total_price'] = calculate_price($_SESSION['cart']);

$_SESSION['items'] = calculate_items($_SESSION['cart']);

}

// Save

if (isset($_POST['save'])) {

foreach ($_SESSION['cart'] as $isbn => $qty) {

if ($_POST[$isbn] == '0') {

unset($_SESSION['cart'][$isbn]);

}else {

$_SESSION['cart'][$isbn] = $_POST[$isbn];

}

}

$_SESSION['total_price'] = calculate_price($_SESSION['cart']);

$_SESSION['items'] = calculate_items($_SESSION['cart']);

}

do_html_header("Your shopping cart");

// Display the cart

if ($_SESSION['cart'] && (array_count_values($_SESSION['cart']))) {

display_cart($_SESSION['cart']);

}else {

echo "

There are no items in your cart


";

}

$target = "index.php";

if ($new) {

$detail = get_book_details($new);

if ($detail['catid']) {

$target = "show_cat.php?catid=".$detail['catid'];

}

}

display_button($target, "continue-shopping", "Continue Shopping");

display_button("checkout.php", "go-to-checkout", "Go To Checkout");

do_html_footer();

?>

show_cat.php

// include function files for this application

require_once('book_sc_fns.php');

session_start();

$catid = $_GET['catid'];

$name = get_category_name($catid);

do_html_header($name);

// Get books

$book_array = get_books($catid);

display_books($book_array);

if (isset($_SESSION['admin_user'])) {

display_button("index.php", "continue", "Continue Shopping");

display_button("admin.php", "admin-menu", "Admin Menu");

display_button("edit_category_form.php?catid=".$catid."", "edit-category", "Edit category");

}else {

display_button("index.php", "continue-shopping", "Continue Shopping");

}

do_html_footer();

?>

说明

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/560666.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

2018.9.15,Arduino—流水灯实验报告

实验任务和目的 通过Arduino控制LED形成流水灯效果 实验条件 Arduino UNO&#xff0c;面包板&#xff0c;6个LED&#xff0c;6个220Ω电阻 实验过程和结果 实验详细步骤&#xff1a; 在各LED正极和Arduino引脚之间串联一个限流电阻&#xff0c;并将LED负极与Arduion的GND相连 …

2018.9.10.Matlab实验一:熟悉Matlab开发环境

一、实验任务和目的 1. 熟悉Matlab的系统环境及基本操作方法。 2. 掌握Matlab的搜索路径及其设置方法。 3. 熟悉Matlab的帮助信息的查阅方法。 二、实验内容 1. 熟悉 Matlab 工作界面的多个常用窗口的及使用方法。 熟悉Command windows、Workspace、Command history、C…

2018.9.10.Matlab实验二:Matlab基本运算

实验二&#xff1a;Matlab基本运算 一、实验任务和目的 1. 掌握变量的定义与数据类型。 2. 掌握变量的初始化方法。 3. 掌握数组、多维数组与子数组的定义、存储、赋值、变换。 4. 掌握逻辑数组的用法。 5. 熟悉MATLAB常用的函数、常用标点和快捷键。 二、实验内容 1. …

2018.9.15,Matlab实验三:字符串、单元数组和结构体

一、实验任务和目的 掌握Matlab的字符串常用函数及其操作方法。掌握Matlab的结构体的基本操作方法。掌握Matlab的元胞数组的基本操作方法。 二、实验内容字符串数组Str[‘hopes, dreams, hold up, old up’]&#xff0c;查找’O’出现的次数和位置。现有三个字符串变量s1“i”…

c++ 不能分配给为0的数组_【嵌入式C】你有想过quot;数组下标quot;为何从0开始吗?...

1、聊一聊相信大家都有看过电影&#xff0c;今天所分享的是其经典背景音乐&#xff0c;或许音乐响起你又会想起那条单纯、善良的秋田犬&#xff01;今天跟大家聊聊一个有意思的话题&#xff0c;C中的数组下标为啥是从0开始?或者说为什么现在大部分的编程语言都会选择从0开始索…

2018.9.19.Matlab实验四:Matlab程序设计

一、实验任务和目的 熟悉程序设计思想。掌握伪代码的编写方法。掌握分支语句和循环结构的用法。 二、实验内容 输入一个百分制成绩&#xff0c;要求输出成绩等级A、B、C、D、E&#xff0c;其中90-100为A&#xff0c;80-89为B&#xff0c;70-79为C&#xff0c;60-69为D&#…

sata接口 图解 定义_SATA协议简介

SATA协议简介1、概述本文档主要介绍SATA的发展历程以及SATA相关协议&#xff0c;为后续SATA驱动框架分析做基础知识准备。2、SATA简介2.1 SATA发展历程2.1.1 PATA硬盘PATA硬盘叫做并行ATA硬盘(Parellel ATA)。为了限制其信号放大系统产生的高噪声&#xff0c;常采用高达5V的电压…

30岁软件测试转产品_SENSORO 产品总监回特入选 2019 年福布斯中国 30 岁以下精英榜...

日前&#xff0c;福布斯中国发布 2019 年度 30 岁以下精英榜&#xff08;30 Under 30&#xff09;&#xff0c;SENSORO&#xff08;北京升哲科技有限公司&#xff09;产品总监回特 成功入选 U30 精英榜企业科技版块。福布斯中国表示&#xff0c;今年技术领域人才辈出&#xff0…

pagehelper插件oracle,带你学习最简单的分页插件PageHelper

引言:PageHelper是国内非常优秀的一款开源的mybatis分页插件&#xff0c;它支持基本主流与常用的数据库&#xff0c; 例如mysql、 oracle、mariaDB、 DB2、 SQLite、Hsqldb等。今天墨白就给大家聊聊PageHelper这款分页插件,下面是PageHelper开源地址,感兴趣的小伙伴可以去看一下…

实验5matlab自定义函数的编写

问题 自定义一个函数&#xff0c;求给定复数的指数、对数、正弦和余弦&#xff0c;并在命令文件中调用该函数。自定义一个函数&#xff0c;计算一行向量中各元素的均值和标准差。求下列方程的根&#xff1a; f(z)exx2xx100.f(z) \ e^{x}x^{2}x^{\sqrt {x}}100\,. f(z) exx2xx…

ic读卡器设置工具_从Matlab被禁来看,给IC教育带来哪些启发?

在上周五看到朋友圈转发包云岗老师就Matlab被禁后在某论坛的发言&#xff0c;在阅读的当时就很有感触&#xff0c;本想当晚就写点东西&#xff0c;不曾想拖到了现在。包老师的梳理的几个点&#xff0c;是结合教学和应用来谈的。在IC教育培训方面&#xff0c;我对这些观点也深以…

arduino光敏+LED+数码管+蜂鸣器综合实验

内容 用光敏控制LED的明暗程度&#xff0c;光敏值在3位数码管上显示&#xff0c;串口输出光敏值&#xff0c;蜂鸣器到一定的值会didi 话不多说&#xff0c;直接上代码&#xff0c;那几个部分拼到一起&#xff0c;多了个数的拆分&#xff0c;让k1k2k3分别等于百位十位个位 代…

server sql 水平分表_springboot集成Shardingsphere进行分库分表

当公司业务量上去之后&#xff0c;单表支撑不了的时候&#xff0c;分库分表就是一个绕不开的话题&#xff0c;小弟最近新入职一家公司&#xff0c;发现这边公司在用ShardingSphere来进行分库分表&#xff0c;之前没接触过这方面&#xff0c;所以就写了个demo学习一下&#xff0…

网鼎杯2020php反序列化,2020-网鼎杯(青龙组)_Web题目 AreUserialz Writeup

0x02 AreUSerialz关于s大写小写问题&#xff0c;可以看p神在圈子里发的&#xff0c;我在最后付上截图考点: php反序列化 php特性 利用链构造1.打开页面得到代码如下:include("flag.php");highlight_file(__FILE__);class FileHandler {protected $op;protected $file…

利用matlab绘制图形

目前存在的一些问题&#xff1a; 1.第一题的两个图像无法重叠 2.最后一个题的第一个图是六瓣&#xff0c;而我写的是八瓣 感谢张同学给我指出来&#xff0c;目前我正在思考解决方法 第一个的话我以为把框缩小就可以重叠了&#xff0c;但是今天试了一下还是分开的&#xff0c;还…

matlab guide对话框+滑动条+弹出式菜单+列表框的使用

文章目录前言matlab数据传递概观对话框创建利用滑动条实现颜色调控利用弹出式菜单选择并输入文本框利用列表框选择并输入文本框前言 我觉得gui无非就是给程序加了件衣服&#xff0c;其实具体的程序我们都会写&#xff0c;我们唯一不明白的是那几个部分数据之间的传递&#xff…

流放之路材质过滤怎么设置_松下除湿机怎么样 松下除湿机款式有哪些型号【详解】...

马上南方就要进入梅雨季节了&#xff0c;潮湿的天气容易滋生细菌&#xff0c;可能会导致人们出现过敏现象&#xff0c;所以很多家庭都选择购买除湿机&#xff0c;现在市场上的除湿机不是很多&#xff0c;其中松下的除湿机比较受欢迎&#xff0c;所以小编我就来跟大家说一说松下…

matlab图形句柄+图形对象+图形对象的属性+对象操作

文章目录前言&#xff1a;图形对象&#xff1a;图形句柄&#xff1a;图形对象的属性&#xff1a;对象的基本操作figure对象(图形窗口)figure()函数&#xff1a;clf()函数清空当前图形窗口&#xff1a;axes坐标轴对象image()line()text()前言&#xff1a; 下面这些是为了更好地…

echart 高度 不用 不撑满_注意厨房台面高度及细节 装出省心舒服 装出事半功倍...

厨房的装修设计最好还是细节做得好&#xff0c;细节做得能达到事半功倍的效果&#xff0c;厨房台面高度如何设计才是最合适呢&#xff1f;我们一起走进包头装修网了解一下吧&#xff01;下面三个台面的设计细节&#xff0c;也许就能让你家的厨房突然变得好用起来——哪怕你可能…