รบกวนช่วยดูโค้ดทีค่ะ หาไม่เจอว่าผิดตรงไหน insert กับ update ไม่ลงเลย
ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา รบกวนช่วยดูโค้ดทีค่ะ หาไม่เจอว่าผิดตรงไหน insert กับ update ไม่ลงเลย
รบกวนช่วยดูโค้ดทีค่ะ หาไม่เจอว่าผิดตรงไหน insert กับ update ไม่ลงเลย
Copy
ภาพนี้การทำงานคือ กด บวก จะเป็น Auto type input ขึนมาค่ะ โดนถ้ามีข้อมูลอยู่แล้วจะโชว์ ถ้าไม่มีจะขึ้นให้กรอกปกติ
ปัญหาคือ พอเพิ่มข้อมูลลงไปไม่ทำอะไรเลย การทำงานขอโค้ดคือ เช็คแถวว่ามีข้อมูลหรือเปล่า
ถ้าไม่ให้ insert ถ้ามีข้อมูลอยู่แล้วให้ update ค่ะ
รบกวนพี่ๆช่วยดูให้หน่อยค่ะ หาไม่เจอจริงๆ
ปัญหาคือ พอเพิ่มข้อมูลลงไปไม่ทำอะไรเลย การทำงานขอโค้ดคือ เช็คแถวว่ามีข้อมูลหรือเปล่า
ถ้าไม่ให้ insert ถ้ามีข้อมูลอยู่แล้วให้ update ค่ะ
รบกวนพี่ๆช่วยดูให้หน่อยค่ะ หาไม่เจอจริงๆ
<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>
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>"); } } }
<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>
Thepaysz
1.46.65.xxx
21-11-2015
22:12:33
คำแนะนำ และการใช้งาน
สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก
- ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา
โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ