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 > insert data เข้า database จาก dynamic elements ไม่ได้ค่ะ



 

insert data เข้า database จาก dynamic elements ไม่ได้ค่ะ

 



Topic : 121421



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



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




submit ข้อมูลเข้า db ไม่ได้ค่ะ ลองทำแล้ว
ดูโค้ดจาก https://www.thaicreate.com/php/php-mysql-multiple-upload-file-to-mysql-not-array.html แล้วก็ยัง งงๆ อยู่

แล้วอีกอย่าง ทำไม function fncCreateSelectOption ถึงใช้กับคอลัมเหมือนใน function CreateSelectOption ไม่ได้คะ ทั้งๆที่ attribute มันเหมือนกัน
ช่วยหน่อยค่ะ T_T



Code (PHP)
<html>
<head>
<title>ThaiCreate.Com JavaScript Add/Remove Element</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<?php
mysql_connect("xxx","root","xxx");
mysql_select_db("xxxx");
$strSQL = "SELECT * FROM member";
$objQuery = mysql_query($strSQL);
?>

<script language="javascript">

		function CreateSelectOption(ele)
	{
		var objSelect = document.getElementById(ele);
		var Item = new Option("", ""); 
		objSelect.options[objSelect.length] = Item;
		
		<?php
	
		$objQuery = mysql_query($strSQL);
		while($objResult = mysql_fetch_array($objQuery))
		{
		?>
		var Item = new Option("<?php echo $objResult["Firstname"];?>", 
		
		"<?php echo $objResult["UserID"];?>"); 
		objSelect.options[objSelect.length] = Item;
		
		<?php
		}
		?>
	}

	function fncCreateSelectOption(ele)
	{
			var objSelect = ele;
			
			var Item = new Option("Thailand", "TH"); 
			objSelect.options[objSelect.length] = Item;

			var Item = new Option("English", "EN"); 
			objSelect.options[objSelect.length] = Item;

			var Item = new Option("United States", "US"); 
			objSelect.options[objSelect.length] = Item;
	}

	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 1 ***//
		newCell = newRow.insertCell(0);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><SELECT NAME=\"txtTitle_"+intLine+"\" ID=\"txtTitle_"+intLine+"\"></SELECT></center>";

		//*** Column 2 ***//
		newCell = newRow.insertCell(1);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"15\" NAME=\"txtFname_"+intLine+"\" ID=\"txtFname_"+intLine+"\"  VALUE=\"\"></center>";
		
		//*** Column 3 ***//
		newCell = newRow.insertCell(2);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"15\" NAME=\"txtLname_"+intLine+"\" ID=\"txtLname_"+intLine+"\"  VALUE=\"\"></center>";
		
			//*** Column 4 ***//
		newCell = newRow.insertCell(3);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><SELECT NAME=\"txtRole_"+intLine+"\" ID=\"txtRole_"+intLine+"\"></SELECT></center>";

		//*** Create Option ***//
	  
		CreateSelectOption("txtTitle_"+intLine)
		fncCreateSelectOption("txtRole_"+intLine)
		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>

<body Onload="CreateNewRow();">
<form name="frmMain" method="post" action="upload_multiple.php">
<table width="445" border="1" id="tbExp">
  <tr>
  
  	<td width="96"><div align="center">Title</div></td>
    
    <td width="171"><div align="center">Firstname</div></td>
    
     <td width="171"><div align="center">Lastname</div></td>
   
    <td width="156"><div align="center">Status</div></td>
  </tr>
</table>
<input type="hidden" name="hdnMaxLine" value="0">
<input name="btnAdd" type="button" id="btnAdd" value="add" onClick="CreateNewRow();">
<input name="btnDel" type="button" id="btnDel" value="delete" onClick="RemoveRow();">
</form>
<input type="submit" name="submitTeam" id="submitTeam" value="Submit">
</body>
</html>




Tag : PHP, Ms Access, HTML/CSS, JavaScript







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2016-02-16 01:08:02 By : um0000um View : 769 Reply : 4
 

 

No. 1



โพสกระทู้ ( 9,553 )
บทความ ( 2 )



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


ครอบโค๊ดด้วย icon พิเศษ ขนขวา ช่องกรอกข้อความ ด้วยครับ ช่วยให้ก๊อปมาทดสอบง่าย หรืออ่านง่าย






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-02-16 08:53:53 By : Chaidhanan
 


 

No. 2



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

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

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

ลองดูตัวนี้ครับ แก้ปัญหา Web Browser แล้ว

URL

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-02-16 10:43:22 By : mr.win
 

 

No. 3



โพสกระทู้ ( 9,553 )
บทความ ( 2 )



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


127.</form>
128.<input type="submit" name="submitTeam" id="submitTeam" value="Submit">


สลับบันทัดกันหรือเปล่า
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-02-16 11:28:09 By : Chaidhanan
 


 

No. 4



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



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


แก้แล้วค่ะ ลองรันมันใช้ได้กับ firefox ได้อยู่แล้ว
แต่งงตอนเก็บลง db ค่ะ ว่าสรุปเราต้องเอาคำไหนมาใช้เป็นตัวแปร
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com JavaScript Add/Remove Element</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<?php
mysql_connect("xxx","xxxx","xxxx");
mysql_select_db("xxx");
$strSQL = "SELECT * FROM member";
$objQuery = mysql_query($strSQL);
?>

<script language="javascript">

		function CreateSelectOption(ele)
	{
		var objSelect = document.getElementById(ele);
		var Item = new Option("", ""); 
		objSelect.options[objSelect.length] = Item;
		
		<?php
	
		$objQuery = mysql_query($strSQL);
		while($objResult = mysql_fetch_array($objQuery))
		{
		?>
		var Item = new Option("<?php echo $objResult["Firstname"];?>", 
		
		"<?php echo $objResult["UserID"];?>"); 
		objSelect.options[objSelect.length] = Item;
		
		<?php
		}
		?>
	}

	function fncCreateSelectOption(ele)
	{
			var objSelect = ele;
			
			var Item = new Option("Thailand", "TH"); 
			objSelect.options[objSelect.length] = Item;

			var Item = new Option("English", "EN"); 
			objSelect.options[objSelect.length] = Item;

			var Item = new Option("United States", "US"); 
			objSelect.options[objSelect.length] = Item;
	}

	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 1 ***//
		newCell = newRow.insertCell(0);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><SELECT NAME=\"txtTitle_"+intLine+"\" ID=\"txtTitle_"+intLine+"\"></SELECT></center>";

		//*** Column 2 ***//
		newCell = newRow.insertCell(1);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"15\" NAME=\"txtFname_"+intLine+"\" ID=\"txtFname_"+intLine+"\"  VALUE=\"\"></center>";
		
		//*** Column 3 ***//
		newCell = newRow.insertCell(2);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"15\" NAME=\"txtLname_"+intLine+"\" ID=\"txtLname_"+intLine+"\"  VALUE=\"\"></center>";
		
			//*** Column 4 ***//
		newCell = newRow.insertCell(3);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><SELECT NAME=\"txtRole_"+intLine+"\" ID=\"txtRole_"+intLine+"\"></SELECT></center>";

		//*** Create Option ***//
	  
		CreateSelectOption("txtTitle_"+intLine)
		CreateSelectOption("txtRole_"+intLine)
		
		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>

<body Onload="CreateNewRow();">
<form name="frmMain" method="post" action="upload_multiple.php">
<table width="445" border="1" id="tbExp">
  <tr>
  
  	<td width="96"><div align="center">Title</div></td>
    
    <td width="171"><div align="center">Firstname</div></td>
    
     <td width="171"><div align="center">Lastname</div></td>
   
    <td width="156"><div align="center">Status</div></td>
  </tr>
</table>
<input type="hidden" name="hdnMaxLine" value="0">
<input name="btnAdd" type="button" id="btnAdd" value="add" onClick="CreateNewRow();">
<input name="btnDel" type="button" id="btnDel" value="delete" onClick="RemoveRow();">

<input type="submit" name="submitTeam" id="submitTeam" value="Submit">
</form>
</body>
</html>




ต้องแก้ตรงไหนคะ รบกวนด้วยค่ะ

Code (PHP)
mysql_connect("localhost","xxx","xxxx") or die (mysql_error());
		mysql_select_db("edpex_db");

		for($i=1;$i<=(int)($_POST["hdnMaxLine"]);$i++)
		{
			
				
				$strSQL = "INSERT INTO assessorteam";
				$strSQL .="(teamTitle,teamFname,teamLname,teamRole) 
				VALUES ('".$_POST["txtTitle_".$i]."',
				'".$_POST["txtFname_".$i]."'
				'".$_POST["txtLname_".$i]."'
				'".$_POST["txtRole_".$i]."')";
					mysql_query($strSQL);
				
		}
mysql_close();

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2016-02-16 14:41:49 By : um0000um
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : insert data เข้า database จาก dynamic elements ไม่ได้ค่ะ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 03
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 อัตราราคา คลิกที่นี่