


Use PHP to add shopping products, PHP to add shopping products_PHP tutorial
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>
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.
This is how you do asynchronous submission using Ajax. . . addtocart();

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

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,

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 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...

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

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�...

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

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