我想将result2的内容(描述,数量,价格,折扣和总数)以及一些添加的变量插入到另一个表(displaybilling)中。
我在一个while循环中将插入放入displaybilling查询中,不知何故它不起作用。对不起我是php和数据库的新手。
下一页的代码
if (isset($_POST['submit'])){
$totalsum = $_POST["total_amt"];
$custname = $_POST["customer_name"];
$paid = $_POST["paid"];
$today=date('d-m-Y');
$outstanding = $totalsum - $paid;
global $connection;
$query = "INSERT INTO displayoutstanding (";
$query.= " cust_name, date, paid, final_total, oustanding";
$query.= ") VALUES (";
$query.= " '{$custname}', '{$today}', {$paid}, {$totalsum}, {$outstanding}";
$query.= ")";
$finished = mysqli_query($connection, $query);
echo "<table border='1'>\n";
echo "<tr>\n";
echo "<th>Services Rendered</th>\n";
echo "<th>Quantity</th>\n";
echo "<th>Price($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "<th>Amount</th>\n";
echo "</tr>";
global $connection;
$sql1="SELECT description,quantity, amount, discount, total FROM invoicesub WHERE cust_name='$custname' GROUP BY description ORDER BY id";
$result2 = mysqli_query($connection, $sql1) or die(mysqli_error($connection));
while ($rows = mysqli_fetch_array($result2)){
echo "<tr>";
echo "<td>" . $rows['description'] . "</td>";
echo "<td>" . $rows['quantity'] . "</td>";
echo "<td>" . $rows['amount'] . "</td>";
echo "<td>" . $rows['discount']. "%" . "</td>";
echo "<td>" ."$". $rows['total'] . "</td>";
echo "</tr>";
$name = $rows['description'];
$today=date('d-m-Y');
$quantity = $rows['quantity'];
$amount = $rows['amount'];
$discount = $rows['discount'];
global $connection;
$query = "INSERT INTO displaybilling (";
$query.= " cust_name, date, description, quantity, price, discount, total_amt";
$query.= ") VALUES (";
$query.= " '{$cname}', '{$today}', '{$name}', {$quantity}, {$amount}, {$discount}, {$total}";
$query.= ")";
$result = mysqli_query($connection, $query);
}
echo "</table>";
echo "Total Amount:";
echo " ";
echo $totalsum;
echo "<br />";
echo "Customer Name:";
echo " ";
echo $custname;
echo "<br />";
echo "Date:";
echo " ";
echo $today;
echo "<br />";
echo "Customer Paid:";
echo " ";
echo $paid;
echo "<br />";
echo "Outstanding fee:";
echo " ";
echo $outstanding;
echo "<br />";
}
?>
代码
echo "<table border='1'>\n";
echo "<tr>\n";
echo "<th>Services Rendered</th>\n";
echo "<th>Quantity</th>\n";
echo "<th>Price($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "<th>Amount</th>\n";
echo "</tr>";
$cname = $_GET["cname"];
global $connection;
$sql1="SELECT description,quantity, amount, discount, total FROM invoicesub WHERE cust_name='$cname' GROUP BY description ORDER BY id";
$result2 = mysqli_query($connection, $sql1) or die(mysqli_error($connection));
while ($rows = mysqli_fetch_array($result2)){
echo "<tr>";
echo "<td>" . $rows['description'] . "</td>";
echo "<td>" . $rows['quantity'] . "</td>";
echo "<td>" . $rows['amount'] . "</td>";
echo "<td>" . $rows['discount']. "%" . "</td>";
echo "<td>" ."$". $rows['total'] . "</td>";
echo "</tr>";
$name = $rows['description'];
$today=date('d-m-Y');
$quantity = $rows['quantity'];
$amount = $rows['amount'];
$discount = $rows['discount'];
global $connection;
$query = "INSERT INTO displaybilling (";
$query.= " cust_name, date, description, quantity, price, discount, total_amt";
$query.= ") VALUES (";
$query.= " '{$cname}', '{$today}', '{$name}', {$quantity}, {$amount}, {$discount}, {$total}";
$query.= ")";
$result = mysqli_query($connection, $query);
}
echo "</table>";
?>
<?php
$sql1="SELECT SUM(total) as total_amt_2 FROM invoicesub WHERE cust_name='$cname'";
$result3 = mysqli_query($connection, $sql1) or die(mysqli_error($connection));
while ($row = mysqli_fetch_array($result3)){
echo "<tr>";
echo "<td>". "Total Amount:" ."$". $row['total_amt_2'] . "</td>";
echo "</tr>";
$sumtotal = $row['total_amt_2'];
echo "<form action=\"invoiceconirm.php\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"total_amt\" value=\"$sumtotal\" />";
echo "<input type=\"hidden\" name=\"cust_name\" value=\"$cname\" />";
echo "Customer Paid:";
echo "<input type=\"text\" name=\"paid\" value=\"\"/>";
echo "<br />";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit\"/>";
echo "<input type=\"button\" value=\"Cancel\" onclick=\"window.location='manage_content.php';\"/>";
echo "</form>";
}
答案 0 :(得分:0)
表单输入的值在引号中......它们只是输出$ sumtotal和$ cname,因此实际上没有信息从php脚本传递到HTML。
这应该有用。
echo "<table border='1'>\n";
echo "<tr>\n";
echo "<th>Services Rendered</th>\n";
echo "<th>Quantity</th>\n";
echo "<th>Price($)</th>\n";
echo "<th>Discount(%)</th>\n";
echo "<th>Amount</th>\n";
echo "</tr>";
$cname = $_GET["cname"];
global $connection;
$sql1="SELECT description,quantity, amount, discount, total FROM invoicesub WHERE cust_name='$cname' GROUP BY description ORDER BY id";
$result2 = mysqli_query($connection, $sql1) or die(mysqli_error($connection));
while ($rows = mysqli_fetch_array($result2)){
echo "<tr>";
echo "<td>" . $rows['description'] . "</td>";
echo "<td>" . $rows['quantity'] . "</td>";
echo "<td>" . $rows['amount'] . "</td>";
echo "<td>" . $rows['discount']. "%" . "</td>";
echo "<td>" ."$". $rows['total'] . "</td>";
echo "</tr>";
$name = $rows['description'];
$today=date('d-m-Y');
$quantity = $rows['quantity'];
$amount = $rows['amount'];
$discount = $rows['discount'];
global $connection;
$query = "INSERT INTO displaybilling (";
$query.= " cust_name, date, description, quantity, price, discount, total_amt";
$query.= ") VALUES (";
$query.= " '{$cname}', '{$today}', '{$name}', {$quantity}, {$amount}, {$discount}, {$total}";
$query.= ")";
$result = mysqli_query($connection, $query);
}
echo "</table>";
?>
<?php
$sql1="SELECT SUM(total) as total_amt_2 FROM invoicesub WHERE cust_name='$cname'";
$result3 = mysqli_query($connection, $sql1) or die(mysqli_error($connection));
while ($row = mysqli_fetch_array($result3)){
echo "<tr>";
echo "<td>". "Total Amount:" ."$". $row['total_amt_2'] . "</td>";
echo "</tr>";
$sumtotal = $row['total_amt_2'];
echo "<form action=\"invoiceconirm.php\" method=\"POST\">";
echo "<input type=\"hidden\" name=\"total_amt\" value=\"".$sumtotal."\" />";
echo "<input type=\"hidden\" name=\"cust_name\" value=\"".$cname."\" />";
echo "Customer Paid:";
echo "<input type=\"text\" name=\"paid\" value=\"\"/>";
echo "<br />";
echo "<input type=\"submit\" name=\"submit\" value=\"Submit\"/>";
echo "<input type=\"button\" value=\"Cancel\" onclick=\"window.location='manage_content.php';\"/>";
echo "</form>";
}