Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > Dynamic Textbox บันทึกข้อมูล php ลง mysql แบบหลายแถวไม่ได้ค่ะ...



 

Dynamic Textbox บันทึกข้อมูล php ลง mysql แบบหลายแถวไม่ได้ค่ะ...

 



Topic : 094585



โพสกระทู้ ( 386 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter



script.php
<script language="javascript">
	
	function CreateNewRow()
	{
		var intLine = parseInt(document.frmMain.hdnMaxLine.value);
		intLine++;
			
		var theTable = document.getElementById("tbExp");
		var newRow = theTable.insertRow(theTable.rows.length)
		newRow.id = newRow.uniqueID

		var newCell
		
		//*** Column No ***//
		newCell = newRow.insertCell(0);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center>"+intLine+"</center>";

		//*** Column type_id ***//
		newCell = newRow.insertCell(1);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		//newCell.setAttribute("OnClick", "OpenPopup('"+intLine+"')");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"type_id[]\" SIZE=\"5\" ID=\"type_id"+intLine+"\" VALUE=\"...\" OnClick=\"OpenPopup('"+intLine+"')\"></center>";	

		//*** Column type_name ***//
		newCell = newRow.insertCell(2);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\"  NAME=\"type_name[]\"  ID=\"type_name"+intLine+"\" VALUE=\"\"></center>";

		//*** Column color_name ***//
		newCell = newRow.insertCell(3);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		//newCell.setAttribute("OnClick", "OpenPopup('"+intLine+"')");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"color_name[]\"  ID=\"color_name"+intLine+"\" VALUE=\"...\" OnClick=\"OpenPopup2('"+intLine+"')\"></center>";	
		
		
		//*** Column unit ***//
		newCell = newRow.insertCell(4);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\"  NAME=\"unit[]\"  ID=\"unit"+intLine+"\" VALUE=\"คัน\"></center>"
	
			//*** Column amount ***//
		newCell = newRow.insertCell(5);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"amount[]\"  ID=\"amount"+intLine+"\" VALUE=\"\" OnChange=\"chkNum(this);textsum("+intLine+");\" onfocus=\"textsum("+intLine+");\" onblur=\"textsum("+intLine+");\" onkeyup=\"textsum("+intLine+");\"></center>";	

			//*** Column price ***//
		newCell = newRow.insertCell(6);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"price[]\"  ID=\"price"+intLine+"\" VALUE=\"\" OnChange=\"chkNum(this);textsum("+intLine+");\" onfocus=\"textsum("+intLine+");\" onblur=\"textsum("+intLine+");\" onkeyup=\"textsum("+intLine+");\" ></center>";	
		document.frmMain.hdnMaxLine.value = intLine;
		
			//*** Column total ***//
		newCell = newRow.insertCell(7);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" NAME=\"total[]\"  ID=\"total"+intLine+"\" VALUE=\"\" OnChange=\"chkNum(this);textsum("+intLine+");\" onfocus=\"textsum("+intLine+");\" onblur=\"textsum("+intLine+");\" onkeyup=\"textsum("+intLine+");\"></center>";	
		document.frmMain.hdnMaxLine.value = intLine;
		
	}
	
	

	function RemoveRow()
	{
		intLine = parseInt(document.frmMain.hdnMaxLine.value);
		if(parseInt(intLine) > 0)
		{
				theTable = document.getElementById("tbExp");				
				theTableBody = theTable.tBodies[0];
				theTableBody.deleteRow(intLine);
				intLine--;
				document.frmMain.hdnMaxLine.value = intLine;
		}	
	}	
</script>



purchase.php
<?	session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="main_style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="css/smoothness/jquery-ui-1.7.2.custom.css">
<title>บันทึกใบสั่งซื้อรถ</title>
</head>
</html>

<? include "script.php";?>
<? include "5.php";?>
<?
	include"connect.php";
	$strSQL = "SELECT * FROM user u ,prefix p WHERE u.user_id = '".$_SESSION['user_id']."' AND u.prefix = p.prefix_id";
	$objQuery = mysql_query($strSQL);
	$objResult = mysql_fetch_array($objQuery);
	$fullname = $objResult['prefix_name'].$objResult['fname']." ".$objResult['lname'];
?>
<table width="778px" height="40" align="center" style="font-size:13px">
<tr>
<td>
<div align="left" style="font-size:13px;"><img src="image/Motorcycle.png" width="45" height="45" /><b>บันทึกใบสั่งซื้อรถ</b></div>
<hr />
</td></tr>
</table>

<body OnLoad="CreateNewRow()">
<form name="frmMain" method="post" action="save_purchase_bill.php">

<fieldset  style="font-size:14px; width:800px; border-color:#666; border-width:1px; ">
<br /><br />
<table width="803" height="40" align="center" style="font-size:13px">
<tr>
	<td width="9%" align="right"><b><u>สาขา :</u></b></td>
    <td width="49%">
    	<input type="text" name="branch_no_1"   id="branch_no_1"   size="5" 	VALUE="" OnClick="OpenPop(1)"   />
        <input type="TEXT" name="branch_name_1" id="branch_name_1" size="40"    value="" />
    </td>
	<td align="right" width="15%"><b><u>เลขที่ใบรับสินค้า :</u></b></td>
    <td width="27%" align="left">
    <input type="text" name="po_id" id="po_id" value="<? echo $PO.'-'. $strNextSeq;?>"class="tbl_box7" size="22"/>
    </td>
</tr>
<tr>
	<td width="9%" align="right"><b><u>แผนก :</u></b></td>
    <td width="49%">
    	<input type="text" name="type_no_1"   id="type_no_1"   size="5" 	VALUE="" OnClick="OpenUp(1)"   />
        <input type="TEXT" name="type_name_1" id="type_name_1" size="40"    value="" />
    </td>
	<td align="right" width="15%"><b><u>วันที่รับรถ :</u></b></td>
    <td align="left">
    	<input name="date_receive" type="text" class="tbl_box1" id="date_receive"  value="<? echo date("d/m/Y");?>" size="25"  />
    </td>
</tr>
<tr>
	<td width="9%" align="right"><b><u>ผู้บันทึก :</u></b></td>
    <td width="49%">
    <input name="receive_name" class="tbl_box8" id="receive_name"  value="<? echo $fullname;?>"  size="53"/>
     <input type="hidden" name="receive_name" id="receive_name" value="<?=$fullname; ?>"  />
    </td>
    <td align="right"><b><u>วันที่ส่ง :</u></b></td>
    <td><input name="date_send" type="text" class="tbl_box1" id="date_send" value="<? echo date("d/m/Y");?>" size="25" /></td>
</tr>
</table>
</fieldset>
<br />
<br />
   <!--
   <div align="right">
   	<a href="javascript:window.close()"><img src="image/exit.png" width="40" height="40" border="0" /> 
    <font color="#003300" size="2"><b>ปิดหน้าต่าง</b></font>
    </a>
 	</div>
    -->
<table  height="78" border="1" id="tbExp" cellpadding="0" cellspacing="0" style="font-size:13px; ">
  <tr>
    <th width="47"><div align="center">ลำดับ </div></th>
    <th width="39"><div align="center">รหัส </div></th>
    <th width="82"><div align="center">รายละเอียด </div></th>
    <th width="81"><div align="center">สี </div></th>
    <th width="64"><div align="center">หน่วย </div></th>
    <th width="40"><div align="center">จำนวน</div></th>
    <th width="97"><div align="center">ราคา:หน่วย (บาท)</div></th>
	<th width="195"><div align="center">รวมเป็นเงิน (บาท)</div></th>
  </tr>
</table>
<input type="hidden" name="hdnMaxLine" value="0" >
<input name="btnAdd" type="button" id="btnAdd" value="+" onClick="CreateNewRow();">
<input name="btnDel" type="button" id="btnDel" value="-" onClick="RemoveRow();">
<input type="submit" name="btnSubmit" value="บันทึกข้อมูล" />
</form>
<script language="javascript">
CreateNewRow();
CreateNewRow();
CreateNewRow();
CreateNewRow();
CreateNewRow();
</script>

</body>
</html>



save.php
<body>
<?
for($i=1;$i<=(int)$_POST["hdnMaxLine"];$i++)
{
	echo $_POST["type_id[]".$i];
	echo "<br>";
	echo $_POST["type_name[]".$i];
	echo "<br>";
	echo $_POST["color_name[]".$i];
	echo "<br>";
}
?>
</body>
</html>






Tag : PHP, MySQL









ประวัติการแก้ไข
2013-05-02 13:49:56
2013-05-02 14:20:55
2013-05-02 14:22:56
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-05-02 13:49:27 By : lookpla26 View : 1080 Reply : 7
 

 

No. 1



โพสกระทู้ ( 386 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter








แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-02 14:23:32 By : lookpla26
 


 

No. 2



โพสกระทู้ ( 1,994 )
บทความ ( 10 )



สถานะออฟไลน์
Facebook Blogger

Code (PHP)
<body>
<?
for($i=1;$i<=(int)$_POST["hdnMaxLine"];$i++)
{
	echo $_POST["type_id"][$i];
	echo "<br>";
	echo $_POST["type_name"][$i];
	echo "<br>";
	echo $_POST["color_name"][$i];
	echo "<br>";
}
?>
</body>
</html>



ประวัติการแก้ไข
2013-05-02 14:46:21
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-02 14:44:55 By : Naizan
 

 

No. 3



โพสกระทู้ ( 386 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter

ตอบความคิดเห็นที่ : 2 เขียนโดย : Naizan เมื่อวันที่ 2013-05-02 14:44:55
รายละเอียดของการตอบ ::
มันก็ยังไม่ขึ้นอ้ะค้ะ

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-02 14:53:19 By : lookpla26
 


 

No. 4



โพสกระทู้ ( 1,994 )
บทความ ( 10 )



สถานะออฟไลน์
Facebook Blogger

เปลี่ยนจาก for เป็น foreach ดูนะครับ
บางทีค่า $_POST["hdnMaxLine"] อาจจะส่งมาไม่ครบ เลยวนลูปไม่ได้

Code (PHP)
<?
foreach($_POST["type_id"] as $key=>$typeId)
{
	echo "type_id :: " ,$_POST["type_id"][$key];
	echo "<br>";
	echo "type_name :: " ,$_POST["type_name"][$key];
	echo "<br>";
	echo "color_name :: " ,$_POST["color_name"][$key];
	echo "<br><hr>";
}
?>

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-02 15:01:20 By : Naizan
 


 

No. 5



โพสกระทู้ ( 386 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter

ได้มาแบบ งงๆ ยังไม่ค่อยเข้าใจคำสั่ง foreach เดี่ยวลองศึกษาดูค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-02 15:04:24 By : lookpla26
 


 

No. 6



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

อันที่จริง ตอบไว้ในกระทู้เก่า ๆ และบทความที่คุณเอามาแล้วครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-02 15:33:32 By : mr.win
 


 

No. 7



โพสกระทู้ ( 386 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter

บันทึกได้เเล้วแต่ว่าบันทึกแค่แถวแรก แถวเดียวอ้ะค้ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-05-02 15:50:15 By : lookpla26
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : Dynamic Textbox บันทึกข้อมูล php ลง mysql แบบหลายแถวไม่ได้ค่ะ...
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่