Php implements the shopping cart function (below), php implements the shopping cart function _ PHP Tutorial

Source: Internet
Author: User
Tags php online
Php implements the shopping cart function (below), and php implements the shopping cart function. Php implements the shopping cart function (below), php implements the shopping cart function, and next I will continue to learn: php implements the shopping cart function (above) 7. implementing a management interface login interface the following php implements the shopping cart function (below), and php implements the shopping cart function

Continue with the previous article:Php implements the shopping cart function (I)

7. implement a management interface


Logon page

Run the following code:
7.1 admin. php

<? Php/*** @ author switch * @ copyright 2015 * main management menu * // The require_once statement is identical to the require statement, the only difference is that PHP will check whether the file has been included, and if so, it will not include it again. Require_once ('Book _ SC _fns.php '); session_start (); if (@ $ _ POST ['username']) & (@ $ _ POST ['passwd']) // log on to {$ username =$ _ POST ['username']; $ passwd =$ _ POST ['passwd']; if (login ($ username, $ passwd )) {$ _ SESSION ['admin _ user'] = $ username;} else {do_html_header ("Problem:"); echo"

You cocould 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 ("Administration"); if (check_admin_user () {display_admin_menu ();} else {echo"

You are not authorized to enter the administration area.

"; Do_html_URL ('login. php', 'login');} do_html_footer ();?>

7.2 login () in the user_auth_fns.php file ()

Function login ($ username, $ password) // log on to {$ conn = db_connect (); // connect to the database if (! $ Conn) return 0; // Check the uniqueness of the user name $ query = "select * from admin where username = '". $ username. "'and password = sha1 ('". $ password. "')"; $ result = $ conn-> query ($ query); if (! $ Result) return 0; if ($ result-> num_rows> 0) return 1; else return 0 ;}

7.3 function check_admin_user () in the user_auth_fns.php file ()

Function check_admin_user () // check whether it is administrator {if (isset ($ _ SESSION ['admin _ user']) return true; else return false ;}

Management Interface

Run the following code:

7.4 function display_admin_menu () in output_fns.php file ()

Function display_admin_menu () // output the administrator menu {?>
Go to main site
Add a new category
Add a new book
Change admin password
<? Php} function display_button ($ target, $ image, $ alt) // Display button {echo"

";}


Add Directory
Directory added
The directory page shows that the Novel directory is added.

Run the following code:
7.5 insert_category_form.php

<? Php/*** @ author switch * @ copyright 2015 * allows the administrator to add a directory table to the database * // The require_once statement and require statement are identical, the only difference is that PHP will check whether the file has been included. if so, it will not contain require_once ('Book _ SC _fns.php '); session_start (); do_html_header (); if (check_admin_user () {display_category_form (); do_html_URL ("admin. php "," Back to administrtion menu ");} else {echo"

You are not authorized to enter the administation area.

";}Do_html_footer () ;?>

7.6 insert_category.php

<? Php/*** @ author switch * @ copyright 2015 * insert a new directory to the database * // The require_once statement is identical to the require statement, the only difference is that PHP will check whether the file has been included. if so, it will not contain 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. "\" cocould not be added to the database.

";}} Else {echo"

You have not filled out the form. Please try again.

";} Do_html_URL (" admin. php "," Back to administration menu ");} else {echo"

You are not authorised to view this page.

";}Do_html_footer () ;?>

Administrator Directory Interface


Directory editing interface-updatable and deleted


Directory updated


The directory is successfully changed on the main interface.

Run the following code:
7.7 edit_category_form.php

<? Php/*** @ author switch * @ copyright 2015 * the form in the administrator editing directory * // The require_once statement is identical to the require statement, the only difference is that PHP will check whether the file has been included, and if so, it will not include it again. 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"

Cocould not retrieve category details.

";} Do_html_URL (" admin. php "," Back to administration menu ");} else {echo"

You are not authorized to enter the administration area.

";}Do_html_footer () ;?>

7.8 edit_category.php

<? Php/*** @ author switch * @ copyright 2015 * update the database directory * // The require_once statement is identical to the require statement, the only difference is that PHP will check whether the file has been included, and if so, it will not include it again. 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 cocould not be updated.

";}} Else {echo"

You have not filled out the form. Please try again.

";} Do_html_URL (" admin. php "," Back to administration menu ");} else {echo"

You are not authorised to view this page.

";}Do_html_footer () ;?>

7.9 admin_fns.php

<? Php/*** @ author switch * @ copyright 2015 * function set used by the management script */function display_category_form ($ category = '') // display the directory form {// if a directory exists, enter the editing mode $ edit = is_array ($ category);?><? Php if ($ edit) // allow deletion of the existing directory {echo"    ";}?>  <? Php} function display_book_form ($ book = '') // display the book form {// if the imported book exists, enter the editing mode $ edit = is_array ($ book);?><? Php if ($ edit) {echo"    ";}?>      <? Php} function display_password_form () // display the change password form {?>

<? Php} function insert_category ($ catname) // Directory insert {$ conn = db_connect (); // database connection $ query = "select * from categories where catname = '". $ catname. "'"; $ result = $ conn-> query ($ query); if ((! $ Result) | ($ result-> num_rows! = 0) return false; $ query = "insert into categories values ('','". $ catname. "')"; $ result = $ conn-> query ($ query); if (! $ Result) return false; else return true;} function insert_book ($ isbn, $ title, $ author, $ catid, $ price, $ description) // book insert {$ conn = db_connect (); // connect to the database $ query = "select * from books where isbn = '". $ isbn. "'"; $ result = $ conn-> query ($ query); if ((! $ Result) | ($ result-> num_rows! = 0) return false; $ 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 directory name {$ conn = db_connect (); // connect to the database $ 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) {$ conn = db_connect (); // connect to the database $ 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) // delete the directory {$ conn = db_connect (); // connect to the database $ query = "select * from books where catid = '". $ catid. "'"; $ result = @ $ conn-> query ($ query); if ((! $ Result) | (@ $ result-> num_rows> 0) // if the directory contains books, return false cannot be deleted; $ query = "delete from categories where catid = '". $ catid. "'"; $ result = @ $ conn-> query ($ query); if (! $ Result) return false; else return true;} function delete_book ($ isbn) // delete a Book {$ conn = db_connect (); // connect to the database $ query = "delete from books where isbn = '". $ isbn. "'"; $ result = @ $ conn-> query ($ query); if (! $ Result) return false; else return true;}?>

7.10 The Directory deletion operation, book addition, update, and deletion operations are basically the same as the above operations. here we will not demonstrate them. you can download the code to view them.

8. expansion
This project creates a simple PHP shopping cart system. We can also make many improvements and improvements to it:

  • In a real online store, you may have to create some order record and implementation systems-in which the user cannot see the order that has been booked.
  • The customer wants to check the processing status of their orders without contacting us. Users should be able to view their previous orders through an authentication method, and can also closely combine operations with personal circumstances. It is also easier for us to collect some user habits.
  • The image of a book can be transmitted to the image directory of the website through FTP and a suitable name for them. You can upload a file to an image insert page to facilitate this operation.
  • You can add user logon, personalized settings, bibliography recommendations, online comments, membership system, and inventory level check. Many functions can be added.

The above is all the code for php to implement the shopping cart function, hoping to help you learn.

Download source code:Shopping cart

Articles you may be interested in:
  • Example of a php shopping cart
  • Php shopping cart instance (Shen Jing)
  • Php shopping cart implementation code
  • Php online shopping mall shopping cart design code sharing
  • PHP updates the number of shopping carts (Form part/PHP processing part)
  • Go deep into the function analysis of the PHP shopping cart module (function description, with source code)
  • Complete php shopping cart implementation code
  • PHP provides a comprehensive shopping cart class.
  • How php uses cookies to implement shopping cart
  • Php shopping cart implementation

Login (below), php implements the shopping cart function. next I will continue to learn: php implements the shopping cart function (on). 7. implement a management interface. the login interface consists of the following...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.