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,030

HOME > PHP > PHP Forum > ช่วยดู code หน่อยค่ะ adapt จากบทความ Create Dynamic Elements และ PHP MySQL Add/Insert Multiple Record



 

ช่วยดู code หน่อยค่ะ adapt จากบทความ Create Dynamic Elements และ PHP MySQL Add/Insert Multiple Record

 



Topic : 087589



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



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




ลองมาหลายวันแล้วค่ะ ไม่ได้สักที
Code mysql_insertpaymentPlan.php (PHP)
<?php
include("mysql_connect.php");
for($i=1;$i<=(int)$_POST["hdnMaxLine"];$i++)
{
if(isset($_POST["submit"]))
{
$paymentplandate=$_POST["paymentplandate_".$i];
$paymentplanamount=$_POST["paymentplanamount_".$i];
$jobplanpercent=$_POST["jobplanpercent_".$i];
$contractId=$_POST["contractId_".$i];

echo $_POST["paymentplandate_".$i];
 echo   $_POST["paymentplanamount_".$i];
 echo $_POST["jobplanpercent_".$i];

$query="INSERT INTO paymentplan(paymentplandate,paymentplanamount,jobplanpercent,contractId) VALUES('$paymentplandate','$paymentplanamount','$jobplanpercent','$contractId')"; 

$result=mysql_query($query) or die(mysql_error());
if($result)
{
echo"Your payment actual's detail recorded";
}else{
echo"cannot record";
}
}
}

?>	    		 


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

		var newCell	
		
		//*** Column 1 ***//
		newCell = newRow.insertCell(0);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name" );
		newCell.innerHTML = "<center><INPUT TYPE=\"DATE\" SIZE=\"5\"  CLASS=\"DatePicker\"  NAME=\"paymentplandate<?=$i;?>_"+intLine+"\" ID=\"date_"+intLine+"\"  VALUE=\"\" ></center>";
													
		//*** Column 2 ***//
		newCell = newRow.insertCell(1);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"INT\" SIZE=\"20\" NAME=\"paymentamount<?=$i;?>_"+intLine+"\" ID=\"paymentplanamount_"+intLine+"\"  VALUE=\"\" ></center>";
		
		//*** Column 3 ***//
		newCell = newRow.insertCell(2);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"VARCHAR\" SIZE=\"5\" NAME=\"jobplanpercent<?=$i;?>_"+intLine+"\"  ID=\"paymentplanpercent_"+intLine+"\" VALUE=\"\"></center>";
		
		//*** Column 4 ***//
		newCell = newRow.insertCell(3);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"HIDDEN\" SIZE=\"5\" NAME=\"contractId<?=$i;?>_"+intLine+"\"  ID=\"contractId_"+intLine+"\" VALUE=\"\"></center>";
		
		document.frm.hdnMaxLine.value = intLine;
	}
	
	function RemoveRow()
	{
		intLine = parseInt(document.frm.hdnMaxLine.value);
		if(parseInt(intLine) > 0)
		{
				theTable = document.getElementById("tbExp");				
				theTableBody = theTable.tBodies[0];
				theTableBody.deleteRow(intLine);
				intLine--;
				document.frm.hdnMaxLine.value = intLine;
		}	
	}	

	function GenerateRow()
	{
		var intRows = parseInt(document.frm.txtCount.value);
		
		for(i=0;i<intRows;i++)
		{
			CreateNewRow();
		}
		$$('input.DatePicker').each( function(el) {
        new DatePicker(el);
		});
	}
</script>
<body>
<!-------- search form-------------->
<form name="searchcontract" method="get" action="<?=$_SERVER['SCRIPT_NAME'];?>">
<table width="90%" border=0 cellpadding=0 cellspacing=0>
<tr>
<td align="right">Search>>>&nbsp;
เลขที่สัญญา :&nbsp;<input name="txtKeyword" type="varchar"  id="txtKeyword" value="<?=$_GET["txtKeyword"];?>"size="6" />
<input name="GO" type="submit" value="GO" />
</td>
</tr>
</table>
</form>
&nbsp;
&nbsp;
<!----------function search----------->
<?
if($_GET["txtKeyword"] != "")
      {
     include("mysql_connect.php");
	$objDB = mysql_select_db("jobstatus");
	// Search By contractId or contractcode
	
	$strSQL = "SELECT * FROM contract  WHERE (contractId LIKE '%".$_GET["txtKeyword"]."%' or contractcode LIKE '%".$_GET["txtKeyword"]."%' )";
	$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]  " );
?>
<?
while($objResult=mysql_fetch_array($objQuery))
{
$contractId=$objResult["contractId"];
?>
<table bgcolor="#99FFFF" width="35%" align="center">
<tr>
<td  width="39%" height="22"><p class="style1"><b>เลขที่สัญญา : <b><?=$objResult["contractcode"];?></b></b></td></td>
<td  width="61%"><p class="style1"><b>ชื่องาน : <b><?=$objResult["jobname"];?></b></b></td>
 </tr>
 <td  width="39%" height="22"><p class="style1"><b>Job No. :</b></td></td>
<td  width="61%"><p class="style1"><b>ชื่องาน :</b></td>
</tr>
<tr>
<td height="22" width="39%"><p class="style1"><b>SubJob No. :</b></td></td>
<td height="22" width="61%"><p class="style1"><b>ชื่องานย่อย :</b></td>
</tr>
<?
}
?>
<?
mysql_close($connect);
}
?>
</table>
<!---insert form--->
<form name="frm" id="frm" action="mysql_insertpaymentPlan.php" method="post" >
<table width="35%" border="0"  align="center"  bgcolor="#FF99FF">
<tr>
<td align="right"><input type="hidden" name="hdnMaxLine" value="0">
<input type="text" name="txtCount" value="1" size="5"><input name="btnCreate" type="button" id="btnCreate" value="เพิ่มจำนวนแถว" onClick="GenerateRow();">
<input name="btnDel" type="button" id="btnDel" value="ลบ" onClick="RemoveRow();">
</td>
</table>

<table width="35%" border="1" id="tbExp" align="center" bgcolor="#FFCCFF">
  <tr>
    <td><div align="center" >วันที่ </div></td>
    <td><div align="center">แผนงบประมาณ (บาท) </div></td>
    <td><div align="center">%แผนงาน</div></td>
  </tr>
</table>

<table width="35%" border=0 cellpadding=0 cellspacing=0 align="center">
<tr >
  <td height="57" colspan="2" ><div align="center">
 <input name="submit" value="Add" type="submit">
 <input name="reset" value="Cancel" onClick="" type="reset">
 </div> 
 </td>
 </tr>
 </table>
</form>
</body>


error ที่เกิดขึ้น "Cannot add or update a child row: a foreign key constraint fails (`jobstatus/paymentplan`, CONSTRAINT `contractId_2` FOREIGN KEY (`contractId`) REFERENCES `contract` (`contractId`))"

พอลอง echo ดู จะแสดงค่าของแถวแรกที่ insert ไป ส่วนแถว 2 3 4....... ไม่ปรากฎ

ขอบคุณมากค่ะ



Tag : PHP, MySQL, HTML/CSS, JavaScript







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-12-04 09:14:13 By : shushu View : 896 Reply : 2
 

 

No. 1



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



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


https://www.thaicreate.com/php/forum/048745.html

ลองดูจาก บทความนี้ดูนะครับ
ผมก็ใช้วิธีการจากบทความนี้ มาปรับดูอ่ะครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-04 09:30:33 By : buaytor
 


 

No. 2



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



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


มันติดตรง FK ค่ะ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-12-04 09:38:04 By : shushu
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยดู code หน่อยค่ะ adapt จากบทความ Create Dynamic Elements และ PHP MySQL Add/Insert Multiple Record
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 01
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 อัตราราคา คลิกที่นี่