|
|
|
รบกวนช่วยแก้ code insert สินค้ามากกว่า 1อย่างทีครับ |
|
|
|
|
|
|
|
code หน้า add สินค้าเพิ่ม
Code (PHP)
<body>
<?php
$objConnect = mysql_connect("localhost","root","abcd1234") or die("Error Connect to Database");
$objDB = mysql_select_db("thaimee");
mysql_query("SET NAMES UTF8");
$strSQL = "SELECT * FROM po2016 WHERE Po_number = '".$_GET["Po_number"]."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
?>
<style type="text/css">
#con {
text-align: center;
}
#con {
text-align: left;
}
#con {
text-align: left;
}
#con {
text-align: left;
}
</style>
<link rel="stylesheet" href="css/style.css">
</head>
<form action="process_addpo_1.php" method="post" />
<table class="login_table1">
<tr>
</tr>
<tr>
</tr>
<tr>
<td>Date</td>
<td><input type="text" name="Date" readonly="readonly" value="<?php echo $objResult["Date"];?>" required/> </td>
</tr>
<tr>
<tr>
<td>Po Number</td><td><input type="text" name="Po_number" readonly="readonly" value="<?php echo $objResult["Po_number"];?>" required/><br /></td>
</tr>
<tr>
<td>Invoice</td><td><input type="text" name="Invoice" readonly="readonly" value="<?php echo $objResult["Invoice"];?>" /><br /></td>
</tr>
<tr>
<tr>
<td>Customer</td><td><input type="text" name="Customers" readonly="readonly" value="<?php echo $objResult["Customers"];?>" /><br /></td>
</tr>
<tr>
<td>Note</td><td><input type="text" name="Note" value="<?php echo $objResult["Note"];?>" /><br /></td>
</tr>
<tr>
<td>Company</td><td><input type="text" name="Company" readonly="readonly" value="<?php echo $objResult["Company"];?>" /><br /></td>
</tr>
<!-- For po -->
<table id="addpotable">
<tr>
<td>Product(T)</td>
<td>Product(E)</td>
<td>Size</td>
<td>Amount</td>
<td>Unit Price</td>
<td>Total</td>
<td>
</tr>
<tr>
<td><input type="text" name="Product_name[]" placeholder="ลูกอมรสน้ำผึ้งผสมมะนาว ตรา Gi Bee" ></td>
<td><input type="text" name="Product_name_eng[]" placeholder="Gi Bee Honey Lemon Tea Candy" required="required" ></td>
<td><input type='text' name='Size[]' placeholder="110 g x 60 bags" style='width: 70px;'></td>
<td><input type='text' name='Amount[]' class='Amount' style='width: 61px;'></td>
<td><input type='text' name='Price[]' class='Price' style='width: 50px;'></td>
<td><input type='text' name='Total[]' class='Total' style='width: 50px;' readonly="readonly"></td>
</tr>
<td><input type="button" class="button" value="Add" onClick="addInput2('po');"></td>
<td><input type="button" class="button" value="Delete" onClick="RemoveRow('po')"></button></td>
</tr>
</table>
<br />
<br />
<table align="center">
<td><input type="submit" value="Save Thaimee" name="TM" class="submitbutton"></form></td>
<td><input type="submit" value="Save FoodTrade" name = "FT" class="submitbutton"></form></td>
</tr>
</table>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script>
var counter2 = 1;
var limit2 = 10;
function addInput2(divName){
if (counter2 == limit2) {
alert("You have reached the limit of adding " + counter2 + " po");
}
else {
// Find a <table> element with id="myTable":
var table = document.getElementById("addpotable");
// Create an empty <tr> element and add it to the 1st position of the table:
var lastRowIndex = table.rows.length -1;
var row = table.insertRow(lastRowIndex);
}
// Insert new cells (<td> elements) at the 1st and 2nd position of the "new" <tr> element:
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 = row.insertCell(5);
// Add some text to the new cells:
cell1.innerHTML = "<input type='text' name='Product_name'>";
cell2.innerHTML = "<input type='text' name='Product_name_eng'>";
cell3.innerHTML = "<input type='text' name='Size' style='width: 70px;'>";
cell4.innerHTML = "<input type='text' name='Amount' class='Amount' style='width: 61px;'>";
cell5.innerHTML = "<input type='text' name='Price' class='Price' style='width: 50px;'>";
cell6.innerHTML = "<input type='text' name='Total' class='Total' style='width: 50px;' readonly='readonly'>";
counter2++;
Cal();
}
{
}
function Cal(){
$('input').parents('tr').each(function(){
$(this).on('keyup',function(){
var w = $(this).find('.Amount').val()?$(this).find('.Amount').val():0;
var l = $(this).find('.Price').val()?$(this).find('.Price').val():0;
var s = parseFloat(w) * parseFloat(l);
$(this).find('.Total').val(s);
});
});
}
$( document ).ready(function() {
Cal();
});
function RemoveRow () {
var tableID = "addpotable";
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
console.log(rowCount);
if(rowCount != 3) {
rowCount = rowCount - 2;
table.deleteRow(rowCount);
}
}
code หน้า process
Code (PHP)
<body>
<?
$objConnect = mysql_connect("localhost","root","abcd1234") or die("Error Connect to Database");
mysql_query("SET NAMES UTF8");
$objDB = mysql_select_db("thaimee");
$Po_number = $_POST['Po_number'];
$Date = date("Y-m-d");
$Invoice = $_POST['Invoice'];
$Customers = $_POST['Customers'];
$Note = $_POST['Note'];
$Company = $_POST['Company'];
$Product_name = $_POST['Product_name'];
$Product_name_eng = $_POST['Product_name_eng'];
$Size = $_POST['Size'];
$Amount = $_POST['Amount'];
$Price = $_POST['Price'];
$Total = $_POST['Total'];
$Po_number = mysql_real_escape_string($Po_number);
$Invoice = mysql_real_escape_string($Invoice);
$Customers = mysql_real_escape_string($Customers);
$Note = mysql_real_escape_string($Note);
$Company = mysql_real_escape_string($Company);
$objConnect = mysql_connect("localhost","root","abcd1234") or die("Error Connect to Database");
mysql_query("SET NAMES UTF8");
$objDB = mysql_select_db("thaimee");
$i = 0;
foreach( $Product_name_eng as $product_name1) {
$query = " INSERT INTO po2016 (Date, Po_number, Invoice, Customers, Note, Company, Product_name, Product_name_eng, Size, Amount, Price, Total) VALUES ('$Date', '$Po_number', '$Invoice', '$Customers', '$Note', '$Company','$Product_name[$i]', '$Product_name_eng[$i]',
'$Size[$i]', '$Amount[$i]', '$Price[$i]', '$Total[$i]');";
if (!mysql_query($query,$objConnect))
{
die('Error: ' . mysql_error());
}
$i++;
}
echo "<script language=\"JavaScript\">";
echo "alert('add');window.location='poall.php';";
echo "</script>";
$sql = "SELECT Supplier_ID,Contact_Person,Company_Fax,Contact_Number from supplier where company_name_english LIKE '".$Company."'";
$result = mysql_query($sql);
if (!$result) {
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $sql;
die($message);
}
while ($row = mysql_fetch_assoc($result)) {
$supplier_contact = $row['Contact_Person'];
$supplier_fax = $row['Company_Fax'];
$supplier_num = $row['Contact_Number'];
}
?>
<?php mysql_close($objConnect); ?>
</body>
</html>
พอเพิ่มสินค้ามากกว่า 1อย่าง จะมีข้อความขึ้นว่า
Warning: Invalid argument supplied for foreach() in C:\AppServ\www\thaimee\28march\process_addpo_1.php on line 41
รบกวนช่วยแก้ให้ทีครับ
Tag : PHP, MySQL, JavaScript
|
ประวัติการแก้ไข 2016-04-20 09:59:20
|
|
|
|
|
Date :
2016-04-20 09:29:22 |
By :
athiwatbuun |
View :
763 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พวก Key มันซ้ำหรือเปล่าครับ
|
|
|
|
|
Date :
2016-04-20 13:30:51 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|