2014-02-23 118 views
-3

我想插入描述,数量,价格,折扣和总数以及一些添加变量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 "&nbsp;"; 
      echo $totalsum; 
      echo "<br />"; 

      echo "Customer Name:"; 
      echo "&nbsp;"; 
      echo $custname; 
      echo "<br />"; 

      echo "Date:"; 
      echo "&nbsp;"; 
      echo $today; 
      echo "<br />"; 

      echo "Customer Paid:"; 
      echo "&nbsp;"; 
      echo $paid; 
      echo "<br />"; 

      echo "Outstanding fee:"; 
      echo "&nbsp;"; 
      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

的表单输入变量的值在引号......他们只是在输出美元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>"; 

      } 
+0

实际上,窗体的值可以被解析到下一页。它正在工作,但我无法插入到数据库中。我会在下一个评论中粘贴下一页的代码 – user3340777

+0

太长了,所以我编辑了这个问题。我将下一页的代码放在问题的下一页代码下 – user3340777