Home  >  Article  >  Backend Development  >  Code 2 about implementing shopping cart in php

Code 2 about implementing shopping cart in php

不言
不言Original
2018-06-19 17:25:161646browse

This article mainly introduces all the codes for implementing the shopping cart function in PHP, and proposes demand analysis, solutions, and database creation to help you easily implement the shopping cart function. Interested friends can refer to it

Continue learning from the previous article: "About the code for implementing shopping cart in PHP 1"

7. Implement a management interface


Login interface

is implemented by the following code:
7.1 admin.php

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("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 The function login() in the user_auth_fns.php file

function login($username,$password) //登录 
 { 
 $conn = db_connect(); //连接数据库 
 
 if(!$conn) 
 return 0; 
 
 //检查用户名唯一性 
 $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 The function check_admin_user() in the user_auth_fns.php file

function check_admin_user() //检查是否是管理员 
 { 
 if(isset($_SESSION['admin_user'])) 
 return true; 
 else 
 return false; 
 }

Management main interface

is implemented by the following code:

7.4 Function display_admin_menu() in the output_fns.php file

function display_admin_menu() //输出管理员菜单 
 { 
 ?> 
 
Go to main site
Add a new category
Add a new book
Change admin password
\"".

"; }


Directory addition
Directory added successfully
You can see more Novel directories on the directory page

Achieved by the following code :
7.5 insert_category_form.php

You are not authorized to enter the administation area.

"; } do_html_footer(); ?>

7.6 insert_category.php

##

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.

"; } 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, Delete


Directory update successful


The directory main interface can see that the directory has been changed successfully


is implemented by the following code:

7.7 edit_category_form.php


Could 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


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 administration menu"); } else { echo "

You are not authorised to view this page.

"; } do_html_footer(); ?>

7.9 admin_fns.php


 
 
"; } ?>
Category Name:
align="center"> "; } ?>
"; } ?>
ISBN:
Book Title:
Book Author:
Category:
Price:
Description:
align="center"> ";?>

Old password:
New password:
Repeat new password:

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) //图书插入 { $conn = db_connect(); //连接数据库 $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) //更改目录名称 { $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) { $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) //删除目录 { $conn = db_connect(); //连接数据库 $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) //删除图书 { $conn = db_connect(); //连接数据库 $query = "delete from books where isbn='". $isbn ."'"; $result = @$conn ->query($query); if(!$result) return false; else return true; } ?>

7.10 Catalog deletion operations, book addition, update, and deletion operations are basically similar to the above operations. They will not be demonstrated here. You can download the code to view

8. Extension

This project was created A fairly simple PHP shopping cart system. We can also make many improvements and enhancements to it:


  • # In a real online store, some order recording and implementation system may have to be established - in this system , the user cannot see the orders that have been booked.

  • Customers want to be able to check on the status of their order without having to contact us. Users should have a means of authentication that enables them to view their previous orders and also allow them to closely tie actions to their personal circumstances. It is also more convenient for us to collect some user habit information.

  • Pictures of the book can be transferred to the site's images directory via a service such as FTP and given an appropriate name. You can upload files to the image insertion page to make this operation easier.

  • You can add user login, personalized settings and book recommendations, online reviews, membership systems, inventory level checks, etc. There are so many features that can be added.

  • The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About the code for implementing the shopping cart in PHP 1


##

The above is the detailed content of Code 2 about implementing shopping cart in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn