zoukankan      html  css  js  c++  java
  • php第二十六节课

    会话购物车

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>
    <?php
    //session_start();//开启session

    //HTTP,无状态性
    //SESSION COOKIE

    //SESSION:存储在服务端的,每个人存一份,可以存储任意类型的数据,默认过期时间15分钟
    //COOKIE:存储在客户端的,每个人存一份,只能存储字符串,默认永不过期

    //$_SESSION["uid"] = "zhangsan";//写入SESSION

    //echo $_SESSION["uid"];

    //setcookie("uid","zhangsan"); //设置COOKIE


    ?>
    <a href="test1.php">跳转</a>
    </body>
    </html>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>
    <?php
    //session_start();
    //echo $_COOKIE["uid"];
    //echo $_SESSION["uid"];
    ?>
    </body>
    </html>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
    <td>水果名称</td>
    <td>水果价格</td>
    <td>水果产地</td>
    <td>水果库存</td>
    <td>操作</td>
    </tr>
    <?php

    include("../DBDA.php");
    $db = new DBDA();

    $sql = "select * from fruit";

    $attr = $db->Query($sql);

    foreach($attr as $v)
    {
    echo "<tr><td>{$v[1]}</td>
    <td>{$v[2]}</td>
    <td>{$v[3]}</td>
    <td>{$v[4]}</td>
    <td><a href='addgwc.php?code={$v[0]}'>加入购物车</a></td></tr>";
    }

    ?>
    </table>

    <a href="gouwuche.php">查看购物车</a>
    </body>
    </html>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>
    <?php
    session_start();

    if(empty($_SESSION["uid"]))
    {
    header("location:login.php");
    }


    echo $_SESSION["uid"];
    ?>
    </body>
    </html>

    <?php
    session_start();
    include("../DBDA.php");
    $db = new DBDA();

    $uid = $_POST["uid"];
    $pwd = $_POST["pwd"];

    $sql = "select count(*) from Users where Uid='{$uid}' and Pwd = '{$pwd}'";

    $r = $db->StrQuery($sql);

    if($r==1)
    {
    $_SESSION["uid"] = $uid;
    header("location:main.php");
    }
    else
    {
    header("location:login.php");
    }

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>
    <h1>登录</h1>
    <form action="loginchuli.php" method="post">
    <div>用户名:<input type="text" name="uid" /></div>
    <div>密码:<input type="text" name="pwd" /></div>
    <div><input type="submit" value="登录" /></div>
    </form>
    </body>
    </html>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>

    <body>
    <table width="100%" border="1" cellpadding="0" cellspacing="0">
    <tr>
    <td>水果名称</td>
    <td>水果价格</td>
    <td>数量</td>
    </tr>
    <?php
    session_start();

    include("../DBDA.php");
    $db = new DBDA();

    $attr = $_SESSION["sg"];

    foreach($attr as $v)
    {
    $sql = "select Name,Price from fruit where Ids='{$v[0]}'";

    $arr = $db->Query($sql);

    echo "<tr><td>{$arr[0][0]}</td>
    <td>{$arr[0][1]}</td>
    <td>{$v[1]}</td></tr>";
    }


    ?>
    </table>
    </body>
    </html>

    <?php
    session_start();

    $code = $_GET["code"];


    //如果第一次点击
    if(empty($_SESSION["sg"]))
    {
    $attr = array(array($code,1));
    $_SESSION["sg"] = $attr;
    }
    else
    {
    //第n次点击,n!=1
    $attr = $_SESSION["sg"];

    //判断该水果师是否已经存在
    if(iscunzai($code))
    {
    foreach($attr as $k=>$v)
    {
    if($v[0]==$code)
    {
    $attr[$k][1] = $v[1]+1;
    }
    }

    $_SESSION["sg"] = $attr;
    }
    else
    {
    $arr = array($code,1);
    array_push($attr,$arr);

    $_SESSION["sg"] = $attr;
    }

    }

    function iscunzai($c)
    {
    $attr = $_SESSION["sg"];

    $b = false;

    foreach($attr as $v)
    {
    $b = $b || in_array($c,$v);
    }

    return $b;
    }

    header("location:showlist.php");

  • 相关阅读:
    docker 数据卷 ---- 进阶篇
    docker 数据卷 ---- 基础篇
    python做基本的图像处理
    conv1d UpSampling1D aotoencoder 自编码代码摘录
    python daal test
    python dict 构造函数性能比较
    CNN autoencoder 进行异常检测——TODO,使用keras进行测试
    利用CNN进行流量识别 本质上就是将流量视作一个图像
    Deep Belief Network简介——本质上是在做逐层无监督学习,每次学习一层网络结构再逐步加深网络
    python pipe stdout 实现cat|grep 功能
  • 原文地址:https://www.cnblogs.com/xiongxiaobai/p/5527200.html
Copyright © 2011-2022 走看看