Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 数组公式和将数组解析到数据库中的问题_Php_Arrays_Forms_Mysqli_Billing - Fatal编程技术网

Php 数组公式和将数组解析到数据库中的问题

Php 数组公式和将数组解析到数据库中的问题,php,arrays,forms,mysqli,billing,Php,Arrays,Forms,Mysqli,Billing,我正在创建一个表单进行计费,我在total_amt_数组上出现了一个致命错误。另外,如何将项目数组解析到数据库中?表单位于CreateInvoice中,invoicesubmit将所有数组添加到数据库中。任何人都可以向我解释为什么我不能对折扣、金额和数量数组求和 还有,有没有人有更简单的方法来计算所有的总金额数组。我搜索了stackoverflow,其他人通过添加整个成本列来获得最终的总成本金额,从而找到最终的总金额 创建发票 <!DOCTYPE html PUBLIC "-//W3C//

我正在创建一个表单进行计费,我在total_amt_数组上出现了一个致命错误。另外,如何将项目数组解析到数据库中?表单位于CreateInvoice中,invoicesubmit将所有数组添加到数据库中。任何人都可以向我解释为什么我不能对折扣、金额和数量数组求和

还有,有没有人有更简单的方法来计算所有的总金额数组。我搜索了stackoverflow,其他人通过添加整个成本列来获得最终的总成本金额,从而找到最终的总金额

创建发票

<!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>Untitled Document</title>


<script type="text/javascript">

var count = 0;


function addTextArea(){
count= count+1;
var div = document.getElementById('name');
div.innerHTML += "<div> <input type='text' name='name[]' value='' "+"id=name"+count+"> </div>";
div.innerHTML += "\n<br />";
var div = document.getElementById('quantity');
div.innerHTML += "<div><input type='text' name='quantity[]' value ='' "+"id=quantity"+count+"></div>";
div.innerHTML += "\n<br />";
var div = document.getElementById('amount');
div.innerHTML += "<div><input type='text' name='amount[]'  value ='' "+"id=amount"+count+"></div>";
div.innerHTML += "\n<br />";
var div = document.getElementById('discount');
div.innerHTML += "<div><input type='text' name='discount[]'  value ='' "+"id=discount"+count+"></div>";
div.innerHTML += "\n<br />";
}

function removeTextArea(){
document.getElementById("name"+count).remove();

document.getElementById("quantity"+count).remove();

document.getElementById("amount"+count).remove();

document.getElementById("discount"+count).remove();
count = count-1;
}

</script>


</head>

<body>

<form  action="invoicesubmit.php" method="POST">
<?php
echo "<table border='2'>\n"; 
echo "<tr>\n"; 
echo "<th>Description</th>\n"; 
echo "<th>Quantity</th>\n"; 
echo "<th>Amount($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "</tr>"; 

echo "<tr>";
echo "<td>"?><input type='text' size="50" name='name[]' value='Examination and Consultation' readonly/><?php "</td>";
echo "<td>"?><input type='text' size="50" name='quantity[]' value='' /><?php "</td>";
echo "<td>"?><input type='text' size="50" name='amount[]' value='' /><?php "</td>";
echo "<td>"?><input type='text' size="50" name='discount[]' value='' /><?php "</td>";
echo "</tr>";

echo "<tr>"; 
echo "<td>"?><div id="name"></div> <?php "</td>"; 
echo "<td>"?><div id="quantity"></div> <?php "</td>"; 
echo "<td>"?><div id="amount"></div> <?php "</td>"; 
echo "<td>"?><div id="discount"></div> <?php "</td>"; 
echo "</tr>";
?>
<br />
<input type="button" value="Add Description" onClick="addTextArea();"> &nbsp;


<input type="button" value="Remove Description" onClick="removeTextArea();"> &nbsp;
<input type="submit" name="submit" value="submit">

</form>

</body>
</html>

无标题文件
var计数=0;
函数addTextArea(){
计数=计数+1;
var div=document.getElementById('name');
div.innerHTML+=“”;
div.innerHTML+=“\n
”; var div=document.getElementById('quantity'); div.innerHTML+=“”; div.innerHTML+=“\n
”; var div=document.getElementById(“金额”); div.innerHTML+=“”; div.innerHTML+=“\n
”; var div=document.getElementById(“折扣”); div.innerHTML+=“”; div.innerHTML+=“\n
”; } 函数removextarea(){ document.getElementById(“name”+count).remove(); document.getElementById(“数量”+计数).remove(); document.getElementById(“金额”+count).remove(); document.getElementById(“折扣”+计数).remove(); 计数=计数-1; }
发票提交

<?php require_once("includes/session.php"); ?>
<?php require_once("includes/db_connection.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php require_once("includes/validation_function.php"); ?>


<?php
if (isset($_POST['submit'])) {
    // Process the form

    $name_array = $_POST['name'];
    $quantity_array = $_POST['quantity'];
    $amount_array = $_POST['amount'];
    $discount_array = $_POST['discount'];

    $total_amt_array = ($amount_array - ($amount_array * ($discount_array/ 100))) * $quantity_array ;

    for ($i =0; $i < count($name_array); $i++) {

        $name = $name_array[$i];
        $quantity = $quantity_array[$i];
        $amount = $amount_array[$i];
        $discount = $discount_array[$i];
        $total_amt = $total_amt_array[$i];

            echo $name;
    echo "<br />";
    echo $quantity;
    echo "<br />";
    echo $amount;
    echo "<br />";
    echo $discount;
    echo "<br />";
    echo $total_amt;
    }
}
/*  
    //validations
    $required_fields = array("name", "quantity", "amount", "discount");
    validate_presences($required_fields);

    $fields_with_max_lengths = array("name" => 200);
    validate_max_lengths($fields_with_max_lengths);



    if (!empty($errors)) {
      $_SESSION["errors"] = $errors;
      redirect_to("create_invoice.php");    
    }*/




        /*
    // 2. Perform database query
    $query = "INSERT INTO invoicesub (";
    $query .= " description, quantity, amount, discount, total";
    $query .= ") VALUES (";
    $query .= " '{$name}', '{$quantity}', '{$amount}', '{$discount}', '{$total}'";
    $query .= ")";

    $result = mysqli_query($connection, $query);



    if ($result) {
        // Success
        $_SESSION["message"] = "Subject created.";

        redirect_to("confirm_invoice.php");
    }


    else {
        // Failure
        $_SESSION["message"] = "Subject creation failed.";
        redirect_to("create_invoice.php");
    }


} else {
    // This is probably a GET request
    redirect_to("create_invoice.php");
} */
?>


<?php
   if (isset($connection)) { mysqli_close($connection); }
?>

首先,你有:

echo "<td>"?><input type='text' size="50" name='amount[]' value='' /><?php "</td>";
                                                      ^^---create an array in $_POST
然后:

此代码归结为:

$total_amt_array = Array - (Array * (Array / 100))) * Array;

在PHP中不能对数组进行乘法/除法。

好的,不使用数组的情况下,有什么方法可以得出总金额的公式吗?
$total_amt_array = ($amount_array - ($amount_array * ($discount_array/ 100))) * $quantity_array ;
$total_amt_array = Array - (Array * (Array / 100))) * Array;