|
 |
|
php นำค่าจาก textbox วนลูป ยังไงครับ [มือใหม่หัดเขียนครับ] |
|
 |
|
|
 |
 |
|
รบกวนพี่ๆครับ ผมมือใหม่หัดเขียนครับ
อันนี้ฟอร์มครับCode (PHP)
<form id="form2[]" name="form2[]" method="post" action="add.php" OnSubmit="return onSave();"/>
<label for="orderno">หมายเลขคำสั่งซื้อ :</label>
<input name="orderno[]" type="text" id="orderno[]" maxlength="13" />
วันที่สั่งซื้อ :
<label for="dateorder"></label>
<input name="dateorder[]" type="date" id="dateorder[]" />
<br />
<br />
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("301l");
// Search
$strSQL = "SELECT * FROM partdata WHERE 1";
if($_POST["supplier_name"] != "0")
{
$strSQL .= " AND (supplier_name = '".$_POST["supplier_name"]."') ";
}
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="624" height="46" border="0">
<tr>
<td width="94" height="16" bgcolor="#999999"><div align="center">รหัสชิ้นส่วน</div>
<div align="center"></div></td>
<td width="250" bgcolor="#999999"><div align="center">ชื่อชิ้นส่วน</div></td>
<td width="99" bgcolor="#999999"><div align="center">จำนวนชิ้นต่อกล่อง</div></td>
<td width="96" bgcolor="#999999"><div align="center">ชื่อบริษัท</div></td>
<td width="81" bgcolor="#999999"><div align="center">จำนวนที่สั่งซื้อ</div></td>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{ $partno=$objResult['partno'];
$partname=$objResult['partname'];
$qty=$objResult['qty'];
$supplier_name=$objResult['supplier_name'];
?>
<tr >
<td height="24"><div align="center">
<input name="txtpartno[]" type="text" value="<?=$objResult['partno'];?>" id="txtpartno" size="10" maxlength="10">
</div></td>
<td><div align="center">
<input name="txtpartname[]" type="text" value="<?=$objResult['partname'];?>" id="txtpartname" size="35" maxlength="50" />
</div></td>
<td><div align="center">
<input name="txtqty[]" type="text" value="<?=$objResult['qty'];?>" id ="txtqty" size="3" maxlength="3" />
</div></td>
<td><div align="center">
<input name="txtsupplier_name[]" type="text" value="<?=$objResult['supplier_name'];?>" id="txtsupplier_name" size="3" maxlength="3" />
</div></td>
<td><div align="center">
<label for="txtqtyorder"></label>
<input name="txtqtyorder[]" type="int" id="qtyorder" size="4" maxlength="4" />
</div></td>
<?
}
?>
</tr>
</table>
<?
global $_POST, $_GET;
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("301l");
$partno = $_POST['partno'];
$partname = $_POST['partname'];
$qty = $_POST['qty'];
$supplier_name = $_POST['supplier_name'];
?>
<p>
<label for="daterecive">วันที่รับมอบสินค้า : </label>
<input type="date" name="daterecive[]" id="daterecive" />
เวลาที่รับมอบ :
<label for="timerecive"></label>
<input type="time" name="timerecive[]" id="timerecive" />
</p>
<p>
<input type="submit" name="button" id="button" value="เพิ่มข้อมูล" />
</p>
</form>
อันนี้ add.phpครับ
Code (PHP)
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("301l");
for($i=0;$i<count($_POST["form2"]);$i++)
{
if($_POST["form2"][$i] != "")
{
$strSQL = "INSERT INTO orderdata SET ";
$strSQL .="partno = '".$_POST["txtpartno"][$i]."' ";
$strSQL .=",partname = '".$_POST["txtpartname"][$i]."' ";
$strSQL .=",qty = '".$_POST["txtqty"][$i]."' ";
$strSQL .=",supplier_name = '".$_POST["txtsupplier_name"][$i]."' ";
$strSQL .=",qtyorder = '".$_POST["txtqtyorder"][$i]."' ";
$strSQL .=",dateorder = '".$_POST["dateorder"][$i]."' ";
$strSQL .=",daterecive = '".$_POST["daterecive"][$i]."' ";
$strSQL .=",timerecive = '".$_POST["timerecive"][$i]."' ";
$strSQL .=",orderno = '".$_POST["orderno"][$i]."' ";
}
}
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
Tag : PHP, MySQL, CakePHP

|
|
 |
 |
 |
 |
Date :
2013-06-27 18:27:47 |
By :
neoleelaw |
View :
1502 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

PHP MySQL Multiple Rows Edit/Update Record
|
 |
 |
 |
 |
Date :
2013-06-27 21:14:04 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|