74th Day Break PHP Login control, main interface display, add shopping cart and place order

Source: Internet
Author: User

Login Interface index.php

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/><title> Priority display Interface </title><link rel=" shortcut icon "type=" Image/x-icon "href=" my-img/ Title.ico "/><form action=" intest.php "method=" POST "><div> User name: <input type=" text "name=" UID "/> </div><div> Password: <input type= "text" name= "word"/></div><div><input type= "Submit" Value= "Submit"/></div></form>

Main interface (fruit shop) index-fruit.php

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/><title> Priority display Interface </title><link rel=" shortcut icon "type=" Image/x-icon "href=" my-img/ Title.ico "/>

PHPSession_Start();if(!isset($_session[' UID '])){ Header(' location:index.php ');}include"Class/uniondatabase-class.php";$db=Newuniondatabase ();$sql= "SELECT * FROM Fruit";$result=$db->query ($sql);foreach($result as $i){ Echo"<tr align= ' center ' > <td>$i[1]</td> <td>$i[2]</td> <td>$i[3]</td> <td>$i[4]</td> <td> <a href= ' intest-shoppingcart.php?code={$i[0]} ' > Add to Cart </a> </td> </tr>";}?></table><br><div> <a href= "index-shoppingcart.php" target= "_blank" >View Shopping Cart</a></div><style type= "Text/css" >table{Border-color:#0F0;}a{Text-decoration:none; Color:#00F;}a:hover{Color:#F00;}div{Position:Absolute; Left: 75%; Font-weight:Old ; Font-size:16px;}</style>

Shopping Cart Interface index-shoppingcart.php

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/><title> Shopping cart </title>

PHPSession_Start();if(!isset($_session[' UID '])){ Header(' location:index.php ');}Else if(isset($_session[' Fruitname '])) { include"Class/uniondatabase-class.php"; $db=Newuniondatabase (); $attr=$_session[' Fruitname ']; foreach($attr as $i) { $sql= "SELECT * from fruit where ids= ' {$i[0]} ' "; $result=$db->query ($sql); Echo"<tr align= ' center ' > <td>{$result[0][1]}</td> <td>{$result[0][2]}</td> <td>{$i[1]}</td> <td> <a href= ' intest-deletefruit.php?code=$i[0] ' > Delete quantity </a> </td> </tr>"; }}></table><br/><div><a href= ' intest-upfruit.php ' > Submit Order </a></div><style Type= "Text/css" >table{Border-color:#0F0;}a{Text-decoration:none; Color:#00F;}a:hover{Color:#F00;}div{Position:Absolute; Left: 80%; Font-weight:Bold; Font-size:16px;}</style>

Log in to the processing interface

<?PHPSession_Start();include"Class/uniondatabase-class.php";$db=Newuniondatabase ();$uid=$_post[' UID '];$word=$_post[' word '];$sql= "SELECT count (*) from user where uid= '$uid' and password= '$word‘";$result=$db-&GT;QUERYSTR ($sql);if($result==1){    $_session[' UID ']=$uid; Header("location:index-fruit.php");}Else{    Header(' location:index.php ');}

Product added to the shopping cart processing interface intest-shoppingcart.php

<?PHPSession_Start();$code=$_get[' Code '];//First time Clickif(!isset($_session[' Fruitname '])){    $attr=Array(Array($code, 1));//array of items and numbers stored    $_session[' Fruitname ']=$attr;}//Click multiple timesElse{    $attr=$_session[' Fruitname ']; if(Fruitisset ($code))    {        foreach($attr  as $k=$i)        {            if($i[0]==$code)            {                $attr[$k][1]=$i[1]+1; }        }        $_session[' Fruitname ']=$attr; }    Else    {        $arr=Array($code, 1); Array_push($attr,$arr); $_session[' Fruitname ']=$attr; }}Header(' location:index-fruit.php ');//a way to determine whether a shopping cart has some kind of fruitfunctionFruitisset ($code){    $attr=$_session[' Fruitname ']; $t=false; foreach($attr  as $i)    {        $t=$t||In_array($code,$i); }    return $t;}

Shopping Cart Product deletion processing interface intest-deletefruit.php

<?PHPSession_Start();$code=$_get[' Code '];$attr=$_session[' Fruitname '];foreach($attr  as $k=$i){    if($i[0]==$code)    {        $attr[$k][1]=$i[1]-1; if($attr[$k][1]==0)        {            Array_splice($attr,$k, 1); }    }    $_session[' Fruitname ']=$attr;}Header(' location:index-shoppingcart.php ');

Order Processing Interface intest-upfruit.php

<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/&GT;&LT;?PHPSession_Start();$Fruit=$_session[' Fruitname '];$Uid=$_session[' UID '];include"Class/uniondatabase-class.php";$db=Newuniondatabase ();$sql 1= "Select UserName from user where uid= '$Uid‘";$UserName=$db-&GT;QUERYSTR ($sql 1);//Get user name$Time=Date("Y-m-d h:i:s", Time());//get the order timeEcho $Uid;Echo $UserName;Echo $Time;$sql 2= "INSERT into order values ('", '$Uid‘,‘$UserName‘,‘$Time‘)";$db->query ($sql 2);foreach($Fruit  as $i){    $sql 3= "INSERT into OrderDetails values (' ', '$Uid‘,‘$i[0] ', '$i[1] ') '; $db->query ($sql 3);}

74th Day Break PHP Login control, main interface display, add shopping cart and place order

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.