2014-02-23 178 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