Table of Contents
Use PHP to add shopping products, PHP to add shopping products
PHP shopping website How to add products in the background and display them in the foreground?
How to prevent the number of items in the shopping cart from being automatically incremented by 1 when refreshing the browser, a shopping website made with php
Home Backend Development PHP Tutorial Use PHP to add shopping products, PHP to add shopping products_PHP tutorial

Use PHP to add shopping products, PHP to add shopping products_PHP tutorial

Jul 13, 2016 am 10:23 AM
shopping website

Use PHP to add shopping products, PHP to add shopping products

<span><span> 1</span> <?<span>php
</span><span> 2</span> <span>session_start</span><span>(); 
</span><span> 3</span> <span>header</span> ( "Content-type: text/html; charset=UTF-8" );                         <span>//</span><span>设置文件编码格式</span>
<span> 4</span> <span>require</span>("system/system.inc.php");                          <span>//</span><span>包含配置文件</span>
<span> 5</span> <span>/*</span><span>*
</span><span> 6</span> <span>    *  1表示添加成功
</span><span> 7</span> <span>    *  2表示用户没有登录
</span><span> 8</span> <span>    *  3表示商品已添加过
</span><span> 9</span> <span>    *  4表示添加时出现错误
</span><span>10</span> <span>    *  5表示没有商品添加
</span><span>11</span> <span>*/</span>
<span>12</span> <span>$reback</span> = '0'<span>;
</span><span>13</span> <span>if</span>(<span>empty</span>(<span>$_SESSION</span>['member'])){ <span>//</span><span>判断用户有没有登录</span>
<span>14</span>     <span>$reback</span> = '2';              <span>//</span><span>没有就返回2</span>
<span>15</span> }<span>else</span><span>{
</span><span>16</span>     <span>$key</span> = <span>$_GET</span>['key'];         <span>//</span><span>判断用户有没有添加商品</span>
<span>17</span>     <span>if</span>(<span>$key</span> == ''){              <span>//</span><span>判断用户有没有添加商品,如果为空就表示没有商品喽</span>
<span>18</span>         <span>$reback</span> = '5';           <span>//</span><span>返回值</span>
<span>19</span>     }<span>else</span><span>{    
</span><span>20</span>         <span>$boo</span> = <span>false</span>;             <span>//</span><span>定义商品有没有被添加</span>
<span>21</span>         <span>$sqls</span> = "select id,shopping from tb_user where name = '".<span>$_SESSION</span>['member']."'"<span>; 
</span><span>22</span>         <span>$shopcont</span> = <span>$admindb</span>->ExecSQL(<span>$sqls</span>,<span>$conn</span><span>);
</span><span>23</span>         <span>if</span>(!<span>empty</span>(<span>$shopcont</span>[0]['shopping'])){  <span>//</span><span>shopping为三维数组,用empty判断商品是否为空</span>
<span>24</span>             <span>$arr</span> = <span>explode</span>('@',<span>$shopcont</span>[0]['shopping']);<span>//</span><span>@分割数组也就是每个商品的值</span>
<span>25</span>             <span>foreach</span>(<span>$arr</span> <span>as</span> <span>$value</span>){ <span>//</span><span>foreach取出每个数组的值</span>
<span>26</span>                 <span>$arrtmp</span> = <span>explode</span>(',',<span>$value</span>);            <span>//</span><span>用explode分割得出商品的俱体信息</span>
<span>27</span>                 <span>if</span>(<span>$key</span> == <span>$arrtmp</span>[0]){                 <span>//</span><span>如果添加的商品等于已添加的商品</span>
<span>28</span>                     <span>$reback</span> = '3';                      <span>//</span><span>那么返回值就表示已添加</span>
<span>29</span>                     <span>$boo</span> = <span>true</span><span>;                         
</span><span>30</span>                     <span>break</span><span>;
</span><span>31</span> <span>                }
</span><span>32</span> <span>            }
</span><span>33</span>             <span>if</span>(<span>$boo</span> == <span>false</span>){              <span>//</span><span>方法一添加商品</span>
<span>34</span>                 <span>$shopcont</span>[0]['shopping'] .= '@'.<span>$key</span>.',1'<span>; 
</span><span>35</span>                 <span>$update</span> = "update tb_user set shopping='".<span>$shopcont</span>[0]['shopping']."' where name = '".<span>$_SESSION</span>['member']."'"<span>;
</span><span>36</span>                 <span>$shop</span> = <span>$admindb</span>->ExecSQL(<span>$update</span>,<span>$conn</span><span>);
</span><span>37</span>                 <span>if</span>(<span>$shop</span><span>){
</span><span>38</span>                     <span>$reback</span> = 1<span>;
</span><span>39</span>                 }<span>else</span><span>{
</span><span>40</span>                     <span>$reback</span> = '4'<span>;
</span><span>41</span> <span>                }
</span><span>42</span> <span>            }
</span><span>43</span>         }<span>else</span><span>{
</span><span>44</span>             <span>$arrtmp</span> = <span>$key</span>.",1";          <span>//</span><span>方法二添加商品</span>
<span>45</span>             <span>$updates</span> = "update tb_user set shopping='".<span>$arrtmp</span>."' where name = '".<span>$_SESSION</span>['member']."'"<span>;
</span><span>46</span>             <span>$result</span> = <span>$admindb</span>->ExecSQL(<span>$updates</span>,<span>$conn</span><span>);
</span><span>47</span>             <span>if</span>(<span>$result</span><span>){
</span><span>48</span>                 <span>$reback</span> = 1<span>;
</span><span>49</span>             }<span>else</span><span>{
</span><span>50</span>                 <span>$reback</span> = '4'<span>;
</span><span>51</span> <span>            }
</span><span>52</span> <span>        }
</span><span>53</span> <span>    }
</span><span>54</span> <span>}
</span><span>55</span> <span>echo</span> <span>$reback</span><span>;
</span><span>56</span> ?></span>
Copy after login

PHP shopping website How to add products in the background and display them in the foreground?

You can use PHP online store program, or you can write it yourself!

If you use an online store program, please read the relevant background instructions in detail. It's actually very simple.

If you have the ability to write it, you can definitely write it yourself, EASY.

How to prevent the number of items in the shopping cart from being automatically incremented by 1 when refreshing the browser, a shopping website made with php

This is how you do asynchronous submission using Ajax. . . addtocart();

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/838914.htmlTechArticleUse PHP to add shopping products, PHP to add shopping products 1? php 2 session_start (); 3 header ( "Content- type: text/html; charset=UTF-8" ); // Set file encoding format 4 require ("system/s...
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Framework Security Features: Protecting against vulnerabilities. Framework Security Features: Protecting against vulnerabilities. Mar 28, 2025 pm 05:11 PM

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

Customizing/Extending Frameworks: How to add custom functionality. Customizing/Extending Frameworks: How to add custom functionality. Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

See all articles