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 กับ update ไม่ลงเลย



 

รบกวนช่วยดูโค้ดทีค่ะ หาไม่เจอว่าผิดตรงไหน insert กับ update ไม่ลงเลย

 



Topic : 120095



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



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



ภาพนี้การทำงานคือ กด บวก จะเป็น Auto type input ขึนมาค่ะ โดนถ้ามีข้อมูลอยู่แล้วจะโชว์ ถ้าไม่มีจะขึ้นให้กรอกปกติ

ss

ปัญหาคือ พอเพิ่มข้อมูลลงไปไม่ทำอะไรเลย การทำงานขอโค้ดคือ เช็คแถวว่ามีข้อมูลหรือเปล่า
ถ้าไม่ให้ insert ถ้ามีข้อมูลอยู่แล้วให้ update ค่ะ

รบกวนพี่ๆช่วยดูให้หน่อยค่ะ หาไม่เจอจริงๆ

Code (PHP)
<script language="javascript">
	function CreateSelectOption(ele)
	{
		var objSelect = document.getElementById(ele);
		var Item = new Option("Thailand", "Thailand"); 
		objSelect.options[objSelect.length] = Item;
		<?
		while($objResult = mysql_fetch_array($objQuery))
		{
		?>
		var Item = new Option("<?=$objResult["country_name_en"];?>", "<?=$objResult["country_name_en"];?>"); 
		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><INPUT TYPE=\"TEXT\" CLASS=\"form-control\" NAME=\"Column1_"+intLine+"\"  ID=\"Column1_"+intLine+"\" VALUE=\"\"></center>";
		//*** Column 5 ***//
		
		//*** Column 2 ***//
		
		newCell = newRow.insertCell(1);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><SELECT NAME=\"Column2_"+intLine+"\" CLASS=\"form-control css-require\" ID=\"Column2_"+intLine+"\"></SELECT></center>";

		//*** Column 3 ***//
		newCell = newRow.insertCell(2);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\"  CLASS=\"form-control\" NAME=\"Column3_"+intLine+"\"  ID=\"Column3_"+intLine+"\" VALUE=\"\"></center>";
		
		//*** Column 4 ***//
		newCell = newRow.insertCell(3);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"DATE\"  CLASS=\"form-control\" NAME=\"Column4_"+intLine+"\"  ID=\"Column4_"+intLine+"\" VALUE=\"\"></center>";
		
		//*** Column 4 ***//
		newCell = newRow.insertCell(4);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"DATE\" CLASS=\"form-control\" SIZE=\"5\" NAME=\"Column5_"+intLine+"\"  ID=\"Column5_"+intLine+"\" VALUE=\"\"></center>";
		//*** Column 4 ***//
		newCell = newRow.insertCell(5);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" CLASS=\"form-control\" SIZE=\"5\" NAME=\"Column6_"+intLine+"\"  ID=\"Column6_"+intLine+"\" VALUE=\"\"></center>";
		//*** Column 4 ***//
		newCell = newRow.insertCell(6);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" CLASS=\"form-control\" SIZE=\"5\" NAME=\"Column7_"+intLine+"\"  ID=\"Column7_"+intLine+"\" VALUE=\"\"></center>";
		//*** Column 4 ***//
		newCell = newRow.insertCell(7);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<INPUT TYPE=\"FILE\"  NAME=\"Column8_"+intLine+"\"  ID=\"Column8_"+intLine+"\" VALUE=\"\">";
		
		 
		
		

		//*** Create Option ***//
		CreateSelectOption("Column2_"+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>



นี่เป็นโค้ดคำสั่ง Code (PHP)
for($i=1;$i<=(int)($_POST["intLine"]);$i++){		  
	 $select7=mysql_query("select *from crew_certificate_personals where cc_fk_cp_id = '".$crews."' and cc_fk_nc_id='".$i."'") or die (mysql_error());
	$num_rows7=mysql_num_rows($select7);
	echo("<script> alert('select');</script>");
	if($num_rows7 == 0){
		if($_POST["Column1_".$i]){
			$rename = date("Y-m-d_His").$_FILES["Column8_".$i]["name"];
		move_uploaded_file($_FILES["Column8_".$i]["tmp_name"],"document/".$rename);
	echo("<script> alert('reanem');</script>");
			$SQL7 = "INSERT INTO name_certificate_personals (nc_formal_name_en,nc_id_namecert,nc_status) VALUES( 
                        '".$_POST["Column1_".$i]."','".$i."', '1')";
             $Query7 =   mysql_query($SQL7);
echo("<script> alert('3');</script>");
		  $strSQL7 = "INSERT INTO crew_certificate_personals (cc_number,cc_date_issued,cc_date_expired,cc_country,cc_place,cc_authority,cc_file,cc_fk_cp_id,cc_fk_nc_id,cc_status) VALUES( 
                        '".$_POST["Column3_".$i]."',
                        '".$_POST["Column4_".$i]."',
                        '".$_POST["Column5_".$i]."',
                        '".$_POST["Column2_".$i]."',
                        '".$_POST["Column6_".$i]."',
                        '".$_POST["Column7_".$i]."',
						'".$rename."',
                        '".$crews."', '".$i."', '1'
                    )";
                 $objQuery7 =   mysql_query($strSQL7);
				 echo("<script> alert('4');</script>");
				 echo ("<script>window.location='application_forms_show.php?id=".$crews."'</script>");
		
		}
	
	}else{ 	
	$SQL7="update name_certificate_personals set 
	   nc_formal_name_en='".$_POST["Column1_".$i]."',
	    nc_id_namecert='".$i."',
		nc_status='1'
		where  nc_id_namecert='".$i."'";
		$Query7 =   mysql_query($SQL7);
	 
	   $strSQL7 = "update crew_certificate_personals set 
	   cc_number='".$_POST["Column3_".$i]."',
	    cc_date_issued='".$_POST["Column4_".$i]."',
		cc_date_expired='".$_POST["Column5_".$i]."',
		cc_country='".$_POST["Column2_".$i]."',
		cc_place='".$_POST["Column6_".$i]."',
		cc_authority='".$_POST["Column7_".$i]."',
		cc_fk_cp_id='".$crews."',
		cc_fk_nc_id='".$i."',
		cc_status='1'
		 where cc_fk_cp_id='".$crews."' and cc_fk_nc_id='".$i."'";
		
                 $objQuery7 =   mysql_query($strSQL7);
			 echo ("<script>window.location='application_forms_show.php?id=".$crews."'</script>");
			 if($_FILES["Column8_".$i]["name"] != ""){
				 
				 $rename = date("Y-m-d_His").$_FILES["Column8_".$i]["name"];
		if(move_uploaded_file($_FILES["Column8_".$i]["tmp_name"],"document/".$rename))
	{
		@unlink("document/".$_POST["hdnOld_".$i]);
		$sql7="update crew_certificate_personals set 
		cc_file='".$rename."' where cc_fk_nc_id='".$i."' and cc_fk_cp_id = '".$crews."'";
		$obj7 = 	mysql_query($sql7);	
			echo ("<script>window.location='application_forms_show.php?id=".$crews."'</script>");
	}
			 
 }
	
	}



นี่ส่วน html ค่ะ

Code (PHP)
	 <table class="table table-striped" id="tbExp">
            	<h3><span>(D). Other Qualifications / Course</span></h3>
                
            <tr align="center">
            
            	<td><b>Description of Cert / Course</b></td>
                <td><b>Country of issue</b></td>
                <td><b>Number</b></td>
                <td><b>Date of Issue</b></td>
                <td><b>Date of Expiry</b></td>
                <td><b>Place of issue</b></td>
                <td><b>Issuing Authority / Body</b></td>
                <td><b>Upload File</b></td>
            </tr>  
            <?php
if(@mysql_num_rows($result_cc_122)>0){
		$i = 1;
while($row_cc_122 = mysql_fetch_array($result_cc_122))
{
?>      
            <tr>
            	
                 <td><input type="text" name="Column1_<?php echo $i ?>" value="<?php echo $row_cc_122["nc_formal_name_en"];?>" class="form-control" /> </td>
               <td>
                	<select class="form-control css-require" name="Column2_<?php echo $i ?>">
                            	<option value="Thailand">Thailand</option>
                            	<?
           							$result = mysql_query("SELECT * FROM addr_countries WHERE country_status = 1 ORDER BY country_name_en");
           							while($country = mysql_fetch_array($result)){
							
        						?>
                    			<option value="<? echo $country['country_name_en'] ?>"
                                	<? if($row['country_name_en']==$country['country_name_en']){?>selected<? }?> ><? echo $country['country_name_en'] ?>
                                </option>
                                <? } ?>
                    </select>                
                </td>
                <td><input type="text" name="Column3_<?php echo $i ?>" value="<?php echo $row_cc_122["cc_number"];?>" class="form-control"/></td>
                <td><input type="date" name="Column4_<?php echo $i ?>" value="<?php echo $row_cc_122["cc_date_issued"];?>"class="form-control"/></td>
                <td><input type="date" name="Column5_<?php echo $i ?>" value="<?php echo $row_cc_122["cc_date_expired"];?>"class="form-control"/></td>
                <td><input type="text" name="Column6_<?php echo $i ?>" value="<?php echo $row_cc_122["cc_place"];?>" class="form-control"/></td>
                <td><input type="text" name="Column7_<?php echo $i ?>" value="<?php echo $row_cc_122["cc_authority"];?>" class="form-control"/></td>  
                <td>
                	<input type="file" name="Column8_<?php echo $i ?>" />
                       <input type="hidden" name="hdnOld_<?php echo $i ?>" value="<?php echo $row_cc_122["cc_file"];?>">
                </td>             
            </tr>
           
            
            <input type="hidden" name="hdnMaxLine" value="<?php echo $i ?>">  
    <?php
$i++;
}
    
}else{  ?>
 <tr>
            	
                 <td><input type="text" name="Column1_1" value="<?php echo $row_cc_122["cc_number"];?>" class="form-control" /> </td>
               <td>
                	<select class="form-control css-require" name="Column2_1">
                            	<option value="Thailand">Thailand</option>
                            	<?
           							$result = mysql_query("SELECT * FROM addr_countries WHERE country_status = 1 ORDER BY country_name_en");
           							while($country = mysql_fetch_array($result)){
							
        						?>
                    			<option value="<? echo $country['country_name_en'] ?>"
                                	<? if($row['country_name_en']==$country['country_name_en']){?>selected<? }?> ><? echo $country['country_name_en'] ?>
                                </option>
                                <? } ?>
                    </select>                
                </td>
                <td><input type="text" name="Column3_1" value="<?php echo $row_cc_122["cc_number"];?>" class="form-control"/></td>
                <td><input type="date" name="Column4_1" value="<?php echo $row_cc_122["cc_date_issued"];?>"class="form-control"/></td>
                <td><input type="date" name="Column5_1" value="<?php echo $row_cc_122["cc_date_expired"];?>"class="form-control"/></td>
                <td><input type="text" name="Column6_1" value="<?php echo $row_cc_122["cc_place"];?>" class="form-control"/></td>
                <td><input type="text" name="Column7_1" value="<?php echo $row_cc_122["cc_authority"];?>" class="form-control"/></td>  
                <td>
                	<input type="file" name="Column8_1" />
                </td>             
            </tr>
           
            
            <input type="hidden" name="hdnMaxLine" value="1">  

    <?php } ?> 
<input name="btnAdd" type="button" id="btnAdd" value="+" onClick="CreateNewRow();">
<input name="btnDel" type="button" id="btnDel" value="-" onClick="RemoveRow();">
      
         </table>
         <center>
          	<input type="submit" name="sub1" class="btn btn-primary" value="Save"/>
            <input type="button" name="button" class="btn btn-danger" value="Cancel"/>
        </center>
    </div>




Tag : PHP, MySQL, HTML/CSS, JavaScript, jQuery







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-11-21 22:03:02 By : thepaysz View : 677 Reply : 1
 

 

No. 1



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



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

ปกติหาเจอง่ายนะครับ เว็บเซิร์ฟเวอร์จะแจ้งว่าบรรทัดไหนที่ error
ถ้ามันไม่แสดง ก็ไล่หาเองโดยการ echo "TEST" ไปเรื่อยๆ ว่ามันหยุดที่จุดไหน ก็แสดงว่า error ก่อนจุดนั้นครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-11-22 10:40:55 By : {Cyberman}
 

   

ค้นหาข้อมูล


   
 

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