dongliyi967823 2014-01-22 22:19
浏览 20
已采纳

PHP html表单没有更新DB [关闭]

I'm new to PHP in general, but I think I have the hang of it. For some reason, the data isn't uploading to the database :/

If you have any idea is wrong, or if this is a bad structure, feel free to express your opinion! Thanks in advance for your help!!

config.php:

    <?php
    $database = "LennysPizza";  // the name of the database.
    $server = "localhost";  // server to connect to.
    $db_user = "root";  // mysql username to access the database with.
    $db_pass = "jdish";  // mysql password to access the database with.
    $link = mysqli_connect($server, $db_user, $db_pass);
    mysqli_select_db($link, $database);
    ?>

submitorder.php:

<!DOCTYPE html>
<?php

 include_once 'functions.php';
 include_once 'config.php';
 $cheeseburger_quantity = $_POST['cheeseburger_quantity'];
 $frenchfries_quantity = $_POST['frenchfries_quantity'];
 $chickenfingers_quantity = $_POST['chickenfingers_quantity'];

 $chickenfingers_totalprice = 4.75 * $chickenfingers_quantity;
 $frenchfries_totalprice = 4.75 * $frenchfries_quantity;
 $cheeseburger_totalprice = 4.75 * $cheeseburger_quantity;
 $totalprice = 
 $cheeseburger_totalprice + 
 $frenchfries_totalprice +
 $chickenfingers_totalprice;

 if($totalprice <= 0){
 header('Location: http://localhost/LennysPizza/index.php');
 exit;
 }  else {

?>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Order Submit</title>
</head>
<body>

    <table border ="1">
        <tr>
            <th>Food:</th>
            <th>Quantity:</th>
            <th>Price:</th>
        </tr>

        <tr>
            <td>Cheeseburger</td>
            <td><?php echo $cheeseburger_quantity; ?></td>
            <td><?php echo '$' .$cheeseburger_totalprice;?></td>
        </tr>

        <tr>
            <td>French Fries</td>
            <td><?php echo $cheeseburger_quantity; ?></td>
            <td><?php echo '$'.$frenchfries_totalprice;?></td>
        </tr>

        <tr>
            <td>Chicken Fingers</td>
            <td><?php echo $chickenfingers_quantity; ?></td>
            <td><?php echo '$' .$chickenfingers_totalprice; ?></td>
        </tr>

        <tr>
            <td>Total:</td>
            <td><?php

    echo '$' .$totalprice;

            ?></td>
        </tr>

    </table>


    <?php


    if(isset($_POST['foodaction']) && isset($_POST['customerfirstname']) &&         isset($_POST['customerlastname']) && isset($_POST['phonenumber'])){

        if($_POST['foodaction']  == "Pickup"){
           echo  "Pickup Order! <br /> Estimated time ready: <b>30 minutes</b> <br /> <br /> <br      />

<form method='post' action='sendorder.php'>
<input type='submit' value='Submit Order'>
</form>
               "

            ;  

       } 

       if($_POST['foodaction'] == "Delivery"){
           if(!empty($_POST['address']) && !empty($_POST['zipcode'])){
           echo "Delivery Order! <br />
           <b>Address</b>:".$_POST['address']. ", ".$_POST['zipcode']."<br /> <br />



"


                   ;



           }else{
               echo "You forgot to add your <b>Address</b> and <b>Zip Code</b>!";
           }

       }

    }else{
               echo "You didn't specify if you want your order to be <b>Delivered</b> or have it be <b>Picked up</b> <br />";
           if(empty($_POST['customerfirstname'])){
               echo 'You also have to fill out the <b>First name</b> field.<br />';
           }

           if(empty($_POST['customerlastname'])){
               echo 'You also have to fill out the <b>Last name</b> field.<br />';
           }

           if(empty($_POST['phonenumber'])){
               if($_POST['phonenumber'] )
               echo 'You also have to fill out the <b>Phone Number</b> field.<br />';
           }
    }

 }


    ?>
</body>
</html>

sendorder.php:

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Thank you!</title>
</head>
<body>
    <?php
    // put your code here
    include_once 'functions.php';
    include_once 'config.php';

    $cheeseburger_quantity = isset($_POST['cheeseburger_quantity']);
    $frenchfries_quantity = isset($_POST['frenchfries_quantity']);
    $chickenfingers_quantity = isset($_POST['chickenfingers_quantity']);

    $cheeseburger_comment = isset($_POST['cheeseburger_comment']);
    $frenchfries_comment = isset($_POST['frenchfries_comment']);
    $chickenfingers_comment = isset($_POST['chickenfingers_comment']);
    $customerfirstname = isset($_POST['customerfirstname']);
    $customerlastname = isset($_POST['customerlastname']);
    $phonenumber = isset($_POST['phonenumber']);
    $address = isset($_POST['address']);
    $zipcode = isset($_POST['zipcode']);


    $insert_delivery = "INSERT INTO orders 
        (cheeseburger_quantity, cheeseburger_comment, frenchfries_quantity, frenchfries_comment,  chickenfingers_quantity, chickenfingers_comment, foodaction, customerfirstname, customerlastname, phonenumber, address, zipcode)
        VALUES ('$cheeseburger_quantity', '$cheeseburger_comment', '$frenchfries_quantity', '$frenchfries_comment', '$chickenfingers_quantity', '$chickenfingers_comment', '$customerfirstname',     '$customerlastname', '$phonenumber', '$address', $zipcode)";

    if(mysqli_query($link, $insert_delivery)){

    echo 'Order Submitted!';
    }
    ?>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • douchenhui5569 2014-01-22 22:29
    关注

    isset() is a boolean test. You want to change:

    $cheeseburger_quantity = isset($_POST['cheeseburger_quantity']);
    

    to:

    if (isset($_POST['cheeseburger_quantity'])) {
        $cheeseburger_quantity = $_POST['cheeseburger_quantity'];
    }
    else {
        $cheeseburger_quantity = 0;
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗