表单POST方法:if(isset($ _ POST [' btn-save']按钮点击后未返回true(可能是由于角度路由(?))

时间:2017-04-25 14:23:26

标签: php mysql

我相当肯定它不能成为角度路由,因为按钮同时具有ng-click和name =" btn-save",一个用于指向主页面哪个有效,另一个用于php部分无效。我花了很多天才解决它。

我考虑过将表单数据传递给ng-model然后传递给js文件以获取角度,通过php文件将其作为mysql调用发布,然后我的下拉列表中有一些值无法传递所以我搁置了这个主意。

有谁可以弄清楚它有什么问题?对不起代码很乱。

addSales.php

<?php 

require_once 'database.php';


//if submit button is clicked submit
if(isset($_POST['btn-save']))
{
$data = json_decode(file_get_contents("php://input")); 

//sotred variables from form
$customer_name= $_POST['customer_name'];
$item_id= $_POST['item_name'];
//retrieve
$item_name = mysqli_query($connect,"SELECT ItemName FROM Items WHERE ItemID = '$item_id");
$country= $_POST['country_name'];
$quantity= $_POST['item_quantity'];
$price= $_POST['item_price'];
$sales_date= $_POST['sales_date'];

//insert sales record

mysqli_query($connect,"INSERT INTO Sales (CustomerName, ItemID, ItemName, Country, Quantity, Price, SalesDate)  VALUES('Awful Days', 17, 'Xanax', 'Singapore', 1, 48.3, 2012-01-02)");

//mysqli_query($connect,"INSERT INTO Sales (CustomerName, ItemID, ItemName, Country, Quantity, Price, SalesDate)  VALUES('$customer_name', $item_id, '$item_name', '$country_name', $quantity, $price, $sales_date)");

//update stock count
mysqli_query($connect,"UPDATE Items SET StockLeft = StockLeft - '$quantity' WHERE ItemID = '$item_id'");


//check stock after each record add
$stockchecker=mysqli_query($connect,"SELECT ItemName FROM Items WHERE StockLeft <= 5");
if($stockchecker != NULL)
{
    $message = $stockchecker + "is running out of stock!";
    echo "<script type='text/javascript'>alert('$message');</script>";
}



//return to index main page
echo "
    <!DOCTYPE html>
    <script>
    function redir()
    {
    alert('Record successfully added.');
    window.location.assign('index.php');
    }
    </script>
    <body onload='redir();'></body>";

}

?>

<form method="post">

<div class="form-group">
    <label for="custName">Customer Name:</label>
    <input type="text" name="customer_name" class="form-control" required/>
</div>    

<div class="form-group">
    <label for="itemName">Item Purchased:</label>
    <?php include "database.php";
        $result = mysql_query("SELECT ItemID, ItemName FROM Items");

        echo "<select name='item_name' class='form-control'>";
        while ($row = mysql_fetch_array($result)) 
        {
            echo "<option value='" . $row['ItemID'] . "'>". $row['ItemID'] . " - " . $row['ItemName'] ."</option>";
        }
        echo "</select>";
    ?>

</div>

<div class="form-group">
    <label for="Country">Country:</label>
    <select name="country_name" class="form-control">
        <option value="Malaysia">Malaysia</option>
        <option value="Thailand">Thailand</option>
        <option value="Singaore">Singapore</option>
        <option value="Phillipines">Phillipines</option>
        <option value="Vietnam">Vietnam</option>
        <option value="Other">Other</option>
    </select>
</div>




<div class="form-group">
    <label for="Quantity">Quantity:</label>
    <input type="text" name="item_quantity" class="form-control" required/>
</div>   

<div class="form-group">
    <label for="itemPrice">Total Price (MYR):</label>
    <input type="text" name="item_price" class="form-control" required/>
</div>

<div class="form-group">
     <label for="dateSold">Date:</label>
     <input type='text' name="sales_date" class="form-control" placeholder="dd/mm/yyyy"/>
</div>


<div class="form-group">
    <button ng-click="save()" type="submit" name="btn-save" class="btn btn-primary">Save</button>
    <button ng-click="cancel()" class="btn btn-primary">Cancel</button>
</div>

0 个答案:

没有答案