如何在多次提交过程中保留价值?

时间:2019-06-02 10:17:32

标签: php sql

我正在建立一个披萨订购网站,我试图获取OnlinePizzaOrderingPage.html上用户选择的披萨,并在ShoppingCartpage.php上输出用户的订单。这仅在用户下订单一次时有效,如果他/她再次下订单,则第一个订单将被覆盖。如何不覆盖第一顺序,以便可以显示第一顺序,然后在第一顺序下方显示第二顺序。

我尝试使用PHP,POST,GET和Javascript。 OnlinePizzaOrderingPage.html上不允许使用按钮。我已包含SQL代码,可能是解决该问题所必需的。

OnlinePizzaOrderingPage.html

    <!DOCTYPE html>
    <html>
    <head>
        <title>Online Pizza Ordering Page</title>
        <link rel="stylesheet" type="text/css" href="mystyle.css">
    </head>
    <body>
        <h1>Online Pizza Ordering Page</h1>
        <a href="Detailedsauceandquantitypage.php?pizza=supreme">
            <img src="supreme.jpg" width="82" height="86" title="Supreme" 
    alt="Supreme">
        </a>
        <a href="Detailedsauceandquantitypage.php?pizza=meatlover">
           <img src="meatlover.jpg" width="82" height="86" 
  title="Meatlover" alt="Meatlover">
        </a>
        <a href="Detailedsauceandquantitypage.php?pizza=hawaii">
            <img src="hawaii.jpg" width="82" height="86" title="Hawaii" 
    alt="Hawaii">
        </a>
        <a href="Detailedsauceandquantitypage.php?pizza=fourseasons">
            <img src="fourseasons.jpg" width="82" height="86" title="Four 
    Seasons" alt="Four Seasons">
       </a>
        <a href="Detailedsauceandquantitypage.php?pizza=vege">
            <img src="vege.jpg" width="82" height="86" title="Vege" 
    alt="Vege">
        </a>
    </body>
    </html>

DetailedSauceandquantitypage.php

    <!DOCTYPE html>
    <html>
    <head>
        <script src="script.js"></script>
        <title>Detailed sauce and quantity page</title>
        <link rel="stylesheet" type="text/css" href="mystyle.css">
    </head>
    <body>
        <h1>Detailed sauce and quantity page</h1>
        <form action="ShoppingCartpage.php" method="POST">
            <!-- set form value to retrieve and pass the selected pizza to 
    the cart -->
            <input type="hidden" name="pizza" value="<?php echo 
    htmlspecialchars($_GET['pizza'], ENT_QUOTES, 'UTF-8', false); ?>">

            <img src="bbq.jpg" alt="BBQ">
            <label for="numberOfSauces">Number of Pizzas (0-100):</label>
            <input type="number" name="bbqPizza" min="0" max="100" 
    value="0">
            <br>
            <img src="tomato.jpg" alt="Tomato">
            <label for="numberOfSauces">Number of Pizzas (0-100):</label>
            <input type="number" name="tomatoPizza" min="0" max="100" 
    value="0"> 
            <br>
            <img src="salsa.jpg" alt="Salsa">
            <label for="numberOfSauces">Number of Pizzas (0-100):</label>
            <input type="number" name="salsaPizza" min="0" max="100" 
    value="0"> 
            <br>
            <input type="submit" value="Add to cart" name="submit">
            <br>
        </form>
    </body>
    </html>

ShoppingCartpage.php

    <!DOCTYPE html>
    <html>
    <head>
        <title>Shopping Cart page</title>
        <link rel="stylesheet" type="text/css" href="mystyle.css">
    </head>
    <body>
       <h1>Shopping Cart page</h1>
        <?php
        // define variables and set to empty values
        $bbqPizza = $tomatoPizza = $salsaPizza = "";

        if ( isset( $_POST['submit'] ) ) {
            $pizza = $_POST['pizza']; //value from first page
            $bbq = $_POST["bbqPizza"];
            $tomato = $_POST["tomatoPizza"];
            $salsa = $_POST["salsaPizza"];
            echo $bbq . " " . $pizza . " pizzas with bbq sauce, " . 
    $tomato . " " . $pizza . " pizzas with tomato sauce and " . $salsa . " 
     " . $pizza . " Spizzas with salsa sauce.";
        }
        ?>
        <br>
        <a href="OnlinePizzaOrderingPage.html">Add more pizzas to cart</a>
        <a href="Checkoutpage.html">Go to checkout</a>
    </body>
    </html>

pizzastore.sql

    -- phpMyAdmin SQL Dump
    -- version 4.0.10.19
    -- https://www.phpmyadmin.net
    --
    -- Host: localhost
    -- Generation Time: Apr 18, 2019 at 02:42 PM
    -- Server version: 5.1.73
    -- PHP Version: 5.3.3

    SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
    SET time_zone = "+00:00";


    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8 */;

    --
    -- Database: `pizzastore`
    --

    -- --------------------------------------------------------

    --
    -- Table structure for table `CUSTOMER`
    --

    CREATE TABLE IF NOT EXISTS `CUSTOMER` (
      `CustID` int(8) NOT NULL,
      `UserName` varchar(16) NOT NULL,
      `Password` varchar(8) NOT NULL,
      `GivenName` varchar(16) NOT NULL,
      `LastName` varchar(16) NOT NULL,
      `Address` varchar(32) NOT NULL,
      `CreditCard` int(16) NOT NULL,
      `Email` varchar(32) NOT NULL,
      PRIMARY KEY (`CustID`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    --
    -- Dumping data for table `CUSTOMER`
    --

    INSERT INTO `CUSTOMER` (`CustID`, `UserName`, `Password`, `GivenName`,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
    `LastName`, `Address`, `CreditCard`, `Email`) VALUES
    (1000, 'AAA', '1234abcd', 'Bill', 'John', '3 First Ave, Eastwood,                         
    Sydney', 2147483647, 'b.john@wsu.edu.au'),
    (2000, 'BBB', 'abcd1234', 'Leon', 'Jack', '1 Third Road, Parramatta, 
    Sydney', 2147483647, 'l.jack@navitas.com');

    -- --------------------------------------------------------

    --
    -- Table structure for table `ORDER`
    --

    CREATE TABLE IF NOT EXISTS `ORDER` (
      `OrderID` int(8) NOT NULL,
      `CustID` int(8) NOT NULL,
      `OrderDate` date NOT NULL,
      `OrderTime` time NOT NULL,
      `OrderStatus` varchar(16) NOT NULL DEFAULT 'Pending',
      PRIMARY KEY (`OrderID`,`CustID`),
      KEY `CustID` (`CustID`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    --
    -- Dumping data for table `ORDER`
    --

    INSERT INTO `ORDER` (`OrderID`, `CustID`, `OrderDate`, `OrderTime`,         
    `OrderStatus`) VALUES
    (1, 2000, '2018-01-01', '12:30:00', 'Pending'),
    (2, 2000, '2017-12-25', '17:00:00', 'Pending'),
    (3, 1000, '2018-01-02', '18:00:00', 'Pending'),
    (4, 1000, '2017-11-01', '20:00:00', 'delivered');

    -- --------------------------------------------------------

    --
    -- Table structure for table `ORDER_DETAILS`
    --

    CREATE TABLE IF NOT EXISTS `ORDER_DETAILS` (
      `OrderID` int(8) NOT NULL,
      `PizzaID` int(8) NOT NULL,
      `SauceID` int(8) NOT NULL,
      `Quantity` int(2) NOT NULL,
      PRIMARY KEY (`OrderID`,`PizzaID`,`SauceID`),
      KEY `PizzaID` (`PizzaID`),
      KEY `SauceID` (`SauceID`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    --
    -- Dumping data for table `ORDER_DETAILS`
    --

    INSERT INTO `ORDER_DETAILS` (`OrderID`, `PizzaID`, `SauceID`,         
    `Quantity`) VALUES
    (1, 222, 101, 2),
    (1, 333, 202, 1),
    (3, 222, 303, 2),
    (3, 555, 101, 1),
    (4, 222, 202, 3),
    (4, 444, 202, 4);

    -- --------------------------------------------------------

    --
    -- Table structure for table `PIZZA`
    --

    CREATE TABLE IF NOT EXISTS `PIZZA` (
      `PizzaID` int(8) NOT NULL,
      `PizzaName` varchar(16) NOT NULL,
      `Price` decimal(4,2) NOT NULL,
      `Size` int(2) NOT NULL,
      `Picture` varchar(30) NOT NULL,
      PRIMARY KEY (`PizzaID`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    --
    -- Dumping data for table `PIZZA`
    --

    INSERT INTO `PIZZA` (`PizzaID`, `PizzaName`, `Price`, `Size`,         
    `Picture`) VALUES
    (111, 'Supreme', '19.95', 7, 'supreme.jpg'),
    (222, 'Veggie', '15.95', 7, 'vege.jpg'),
    (333, 'Hawaii', '16.95', 7, 'hawaii.jpg'),
    (444, 'Meatlover', '19.95', 7, 'meatlover.jpg'),
    (555, 'Four seasons', '22.95', 7, 'fourseasons.jpg');

    -- --------------------------------------------------------

    --
    -- Table structure for table `SAUCE`
    --

    CREATE TABLE IF NOT EXISTS `SAUCE` (
      `SauceID` int(8) NOT NULL,
      `SauceName` varchar(16) NOT NULL,
      `SauceCost` decimal(4,2) NOT NULL,
      `SaucePic` varchar(20) NOT NULL,
      PRIMARY KEY (`SauceID`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    --
    -- Dumping data for table `SAUCE`
    --

    INSERT INTO `SAUCE` (`SauceID`, `SauceName`, `SauceCost`, `SaucePic`)                 
    VALUES
    (101, 'BBQ', '5.95', 'bbq.jpg'),
    (202, 'Hot chilli', '4.95', 'salsa.jpg'),
    (303, 'Tomato', '4.95', 'tomato.jpg');

    --
    -- Constraints for dumped tables
    --

    --
    -- Constraints for table `ORDER`
    --
    ALTER TABLE `ORDER`
      ADD CONSTRAINT `ORDER_ibfk_1` FOREIGN KEY (`CustID`) REFERENCES         
    `CUSTOMER` (`CustID`) ON UPDATE CASCADE;

    --
    -- Constraints for table `ORDER_DETAILS`
    --
    ALTER TABLE `ORDER_DETAILS`
      ADD CONSTRAINT `ORDER_DETAILS_ibfk_1` FOREIGN KEY (`PizzaID`)         
    REFERENCES `PIZZA` (`PizzaID`) ON UPDATE CASCADE,
      ADD CONSTRAINT `ORDER_DETAILS_ibfk_4` FOREIGN KEY (`OrderID`)         
    REFERENCES `ORDER` (`OrderID`) ON UPDATE CASCADE,
      ADD CONSTRAINT `ORDER_DETAILS_ibfk_5` FOREIGN KEY (`SauceID`)         
    REFERENCES `SAUCE` (`SauceID`);

    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

我希望结果将是在ShoppingCartpage.php上输出的第一个订单,而第二个订单将在第一个订单下方输出。实际结果是第二个命令仅覆盖了第一个命令,而第一个命令消失了。

0 个答案:

没有答案