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

HOME > PHP > PHP Forum > ช่วยดูโค้ด insert into หน่อยค่ะ ไม่สามารถบันทึกลงฐานข้อมูลได้



 

ช่วยดูโค้ด insert into หน่อยค่ะ ไม่สามารถบันทึกลงฐานข้อมูลได้

 



Topic : 085304

Guest




หน้าฟอร์มค่ะ

Code (PHP)
<!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" />
<title>Overtime Requisition Form</title>
<style type="text/css">
body,td,th {
	font-size: small;
}
a:link {
	color: #000;
}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
</style>
<style type="text/css">
#Bar_process{
	z-index:100;
	visibility:hidden;
	position:absolute;
	text-align:center;
	width:416px;
	left: 155px;
	top: 347px;
	height: 34px;
}
</style>

<script language="JavaScript" src="date-picker.js"></script>
<script type="text/javascript" src="jquery-1.8.2.min.js"></script>
<script language="javascript">
	function OpenPopup(intLine)
	{
		window.open('getPoint.php?Line='+intLine,'myPopup','width=650,height=200,toolbar=0, menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0');
	}
	
	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 EmployeeID ***//
		newCell = newRow.insertCell(1);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"txtEmp_id"+intLine+"\" ID=\"txtEmp_id"+intLine+"\" VALUE=\"\"></center>";
		
		
		//*** Column EmployeeName ***//
		newCell = newRow.insertCell(2);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"20\" NAME=\"txtEmp_name_"+intLine+"\" ID=\"txtEmp_name_"+intLine+"\" VALUE=\"\"></center>";
		

		//*** Column Employeesurname ***//
		newCell = newRow.insertCell(3);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"20\" NAME=\"txtEmp_surname_"+intLine+"\" ID=\"txtEmp_surname_"+intLine+"\"  VALUE=\"\"></center>";
		
		//*** Column RouteIdCountry Code ***//
		newCell = newRow.insertCell(4);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"txtRid_"+intLine+"\"  ID=\"txtRid_"+intLine+"\" VALUE=\"\"></center>";
		//*** Create Option ***//
		//CreateSelectOption("txtCountryCode_"+intLine)
		
		//*** Column RouteName ***//
		newCell = newRow.insertCell(5);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"20\" NAME=\"txtRname_"+intLine+"\"  ID=\"txtRname_"+intLine+"\" VALUE=\"\"></center>";
	
			//*** Column Used ***//
		newCell = newRow.insertCell(6);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><INPUT TYPE=\"TEXT\" SIZE=\"10\" NAME=\"txtUsed_"+intLine+"\"  ID=\"txtUsed_"+intLine+"\" VALUE=\"\"></center>";	

			//*** Column 7 ***//
		newCell = newRow.insertCell(7);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		//newCell.setAttribute("OnClick", "OpenPopup('"+intLine+"')");
		newCell.innerHTML = "<center><INPUT TYPE=\"BUTTON\" NAME=\"btnPopup_"+intLine+"\"  ID=\"btnPopup_"+intLine+"\" VALUE=\"...\" OnClick=\"OpenPopup('"+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>
</head>

<body OnLoad="CreateNewRow();">
 <form name="frmMain" method="post" action="save.php" enctype="multipart/form-data" onsubmit="return upload();" target="uploadtarget">
  <table width="833" height="546" border="0" align="center">
    <tr>
      <td colspan="7" align="center">
	  <!-- Header -->
	  <? include("menu.php");?></td>
    </tr>
    <tr>
      <td colspan="7" align="center">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="7" align="center"><h1><strong>Overtiame Requisition Form</strong></h1></td>
    </tr>
    <tr>
      <td height="36">&nbsp;</td>
      <td>&nbsp;</td>
      <td colspan="2">&nbsp;</td>
      <td colspan="2" align="right">DATE</td>
      <td align="center">
	  <?
$ThMonth = array("มกราคม","กุมภาพันธ์","มีนาคม","เมษายน","พฤษภาคม","มิถุนายน","กรกฏาคม","สิงหาคม","กันยายน","ตุลาคม","พฤศจิกายน","ธันวาคม");
$j = date("j");
$n = $ThMonth[date("n")-1];
$y = date("Y")+543;
echo "$j $n $y";
?></td>
    </tr>
    <tr>
      <td width="62" height="34" align="left">SECTION :     </td>
      <td width="125"><select name="section">
			<option value=""><- Select -></option>
			<?
			 include("config.inc.php");
			$strSQL = "SELECT * FROM section ORDER BY Section_name ASC";
			$objQuery = mysql_query($strSQL);
			while($objResuut = mysql_fetch_array($objQuery))
			{
			?>
			<option value="<?=$objResuut["Section_id"];?>"><?=$objResuut["Section_name"];?></option>
			<?
			}
			?>
		  </select></td>
      <td colspan="2" align="right">DEPARTMENT :</td>
      <td colspan="2"><select name="department">
      <option value=""><- Select -></option>
			<?
			 include("config.inc.php");
			$strSQL = "SELECT * FROM department ORDER BY Department_name ASC";
			$objQuery = mysql_query($strSQL);
			while($objResuut = mysql_fetch_array($objQuery))
			{
			?>
			<option value="<?=$objResuut["Department_id"];?>"><?=$objResuut["Department_name"];?></option>
			<?
			}
			?>
		  </select></td>
      <td width="215">&nbsp;</td>
    </tr>
    <tr>
      <td height="36" align="left">Time :
        <p><br />
      </p></td>
      <td height="36" align="left" valign="top">
      <select name="ot">
			<option value=""><- Select -></option>
			<?
			 include("config.inc.php");
			$strSQL = "SELECT * FROM type_ot";
			$objQuery = mysql_query($strSQL);
			while($objResuut = mysql_fetch_array($objQuery))
			{
			?>
			<option value="<?=$objResuut["Type_OT_id"];?>"><?=$objResuut["Type_Ttime"];?></option>
			<?
			}
			?>
		  </select></td>
      <td width="43"><p><br />
      </p></td>
      <td width="80">&nbsp;</td>
      <td width="139" valign="top">&nbsp;</td>
      <td width="139" align="right" valign="top">DATE</td>
      <td valign="top">
       <SCRIPT LANGUAGE="javascript">
            {
                self.name="BODY"
            }
            function calpopup(Ink){
                window.open(Ink,"calendar","height=250,width=250,scrollbars=no")
            }
            </SCRIPT>
            <!-- จบใส่เพื่อ เพื่อให้ date picker ทำงาน.. -->

            <!-- ใส่เพื่อ เพื่อให้ date picker ทำงาน.. -->
            <script language='javascript' src='popcalendar.js'></script>
            <!-- จบใส่เพื่อ เพื่อให้ date picker ทำงาน.. -->
      <input type="text" name="start_date" maxlength ="10" size="10">
      <script language='javascript'>
             if (!document.layers) {
				 document.write("<input type=button onclick='popUpCalendar(this, frmMain.start_date, \"yyyy-mm-dd\")' value='date'style='font-size:11px'>")
                    }
        </script>
      </tr>
    <tr>
      <td height="6" colspan="7" valign="top"><hr/></td>
    </tr>
    <tr>
      <td height="85" colspan="2" valign="top">DESCRIPTION OF WORK :</td>
      <td colspan="4"><label for="deswork"></label>
      <textarea name="deswork" id="deswork" cols="45" rows="5"></textarea></td>
      <td align="center">&nbsp;</td>
    </tr>
  </table>
  <table width="833" border="0" align="center">
    <tr>
      <td width="149" height="35">REASON FOR TO WORK : </td>
      <td width="68" height="35">1.Plan</td>
      <td width="187"><table width="187" border="0">
        <tr>
          <td><input name="chwork[]" type="checkbox" id="r1" value=" Production Planning. ">1.1 Production Planning</td>
        </tr>
    </table></td>
      <td width="187"><table width="187" border="0">
        <tr>
          <td><input name="chwork[]" type="checkbox" id="r2" value=" Maintenance.">1.2 Maintenance</td>
        </tr>
    </table></td>
      <td width="220"><table width="187" border="0">
        <tr>
          <td><input name="chwork[]" type="checkbox" id="r3" value=" Calibration.">1.3 Calibration</td>
        </tr>
      </table></td>
    </tr>
    <tr>
      <td height="35" colspan="2"></td>
      <td><table width="187" border="0">
        <tr>
          <td><input name="chwork[]" type="checkbox" id="r4" value=" Audit.">1.4 Audit</td>
        </tr>
      </table></td>
      <td><table width="187" border="0">
        <tr>
          <td><input name="chwork[]" type="checkbox" id="r5" value=" Project Inprovement.">1.5 Project Inprovement</td>
        </tr>
      </table></td>
      <td></td>
    </tr>
    <tr>
      <td height="35"></td>
      <td height="35" valign="top">2.Unplanned</td>
      <td colspan="2"><table width="220">
        <tr>
          <td width="193">
            <input type="checkbox" name="reason[]" value="Urgent Build." id="reason_0"> 
            2.1 Urgent Build</td>
        </tr>
        <tr>
          <td><label>
            <input type="checkbox" name="reason[]" value="Material Shortage." id="reason_1" />
            2.2 Material Shortage</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="checkbox" name="reason[]" value="Machine Brekdown." id="reason_2" />
            2.3 Machine Breakdown</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="checkbox" name="reason[]" value="Catch up Cap." id="reason_3" />
            2.4 Catch up Cap.</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="checkbox" name="reason[]" value="Catch up Machine Brekdown." id="reason_4" />
            2.5 Catch up Machine Breakdown</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="checkbox" name="reason[]" value="Engineering/Repai." id="reason_5" />
            2.6 Engineering/Repair</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="checkbox" name="reason[]" value="Rework." id="reason_6" />
            2.7 Rework</label></td>
        </tr>
      </table></td>
      <td colspan="2"><table width="220">
        <tr>
          <td width="193"><label>
            <input type="checkbox" name="reason[]" value="Machine Change Over." id="reason_7" />
            2.8 Machine Change Over</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="checkbox" name="reason[]" value="Qualify Part/MC/Fixture." id="reason_8" />
            2.9 Qualify Part/MC/Fixture</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="checkbox" name="reason[]" value="Receiving." id="reason_9" />
            2.10 Receiving</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="checkbox" name="reason[]" value="Analysis/Specil Test." id="reason_10" />
            2.11 Analysis/Specil Test</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="checkbox" name="reason[]" value="Pilot &amp; Sample Test." id="reason_11" />
            2.12 Pilot &amp; Sample Test</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="checkbox" name="reason[]" value="Traning &amp; Development." id="reason_12" />
            2.13 Traning &amp; Development</label></td>
        </tr>
        <tr>
          <td><label>
            <input type="checkbox" name="reason[]" value="Diving." id="reason_13" />
            2.14 Diving</label></td>
        </tr>
      </table></td>
    </tr>
    <tr>
    <td height="15" colspan="6"><hr/></td>
    </tr>
  </table>

  <table width="833" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td>&nbsp;</td>
    </tr>
  </table>

<table width="833" border="1" align="center" id="tbExp">
  <tr>
    <td width="49"><div align="center">No </div></td>
    <td width="81"><div align="center">EmpID </div></td>
    <td width="169"><div align="center">Employee's Name </div></td>
    <td width="169"><div align="center">Surename</div></td>
    <td width="152"><div align="center">Bus Route</div></td>
    <td width="91"><div align="center">Sup Bus Route </div></td>
	<td width="71"><div align="center">Reason </div></td>
	<td width="94"><div align="center">Popup </div></td>
  </tr>
  </table>
 
  <table width="833" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td> <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();"></td>
    </tr>
  </table>
  <table width="833" border="0" align="center">
    <tr>
      <td colspan="9">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="3">HR : Recorder </td>
      <td colspan="4">&nbsp;</td>
    </tr>
  </table>
  <table width="833" border="0" align="center">
     <tr>
       <td width="147" align="center">&nbsp;</td>
       <td width="229" align="right"><input type="submit" name="ok" id="ok" value="ตกลง" /></td>
       <td width="61" align="center">&nbsp;</td>
       <td width="115" align="left"><input type="reset" name="cancel" id="cancel" value="ยกเลิก" /></td>
       <td width="255" align="center">&nbsp;</td>
    </tr>
  </table>
</form>
<p>&nbsp;</p>
</body>
</html>



หน้า save ค่ะ
Code (PHP)
<!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" />
<title>Untitled Document</title>
</head>

<body>
<?
include("config.inc.php");
$today="$y-$n-$j";
for($i=1;$i<=$_POST["hdnMaxLine"];$i++)
{
	if($_POST["txtEmp_id$i"] != "")
	{
$strSQL = "INSERT INTO otreq ";
$strSQL.= "(OTReq_id,User_User_id,Scheduling_Bus_Scheduling_Bus_id,OTReq_datesend,OTReq_section,OTReq_department,OTReq_time,OTReq_datework,OTReq_plan,
OTReq_unplan,Emp_id,Emp_name,Emp_surname,BusAp_name,BusRoute_Bus_id)";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["today()$i"]."','".$_POST["section$i"]."','".$_POST["department$i"]."' ";
$strSQL .=",'".$_POST["ot$i"]."','".$_POST["start_date$i"]."') ";
$strSQL .="('".$_POST["deswork$i"]."','".$_POST["chwork[]$i"]."','".$_POST["reason[]$i"]."' ";
$strSQL .=",'".$_POST["txtEmp_id$i"]."','".$_POST["txtEmp_name_$i"]."') ";
$strSQL .="('".$_POST["txtEmp_surname_$i"]."','".$_POST["txtRname_$i"]."','".$_POST["txtRid_$i"]."' ";
$objQuery = mysql_query($strSQL);
	}
}
if($objQuery)
{
	echo "Save Done.";
}
else
{
	echo "Error Save [".$strSQL."]";
}
?>
</body>
</html>


มัน error แบบนี้ค่ะ Error Save[]



Tag : PHP, MySQL







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2012-10-11 17:33:38 By : moha View : 1003 Reply : 2
 

 

No. 1



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



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


ลอง
Code (PHP)
echo $strSQL;

ก่อนบรรทัด
Code (PHP)
$objQuery = mysql_query($strSQL);


แล้วเอาที่ echo ออกมาไปลองรันใน MySQL ดูครับ ว่ามัน INSERT ได้มั้ย ถ้าไม่ได้ copy ที่ echo ออกมามาแปะไว้หน่อยครับ Syntax ของ SQL น่าจะผิด ลองดูครับ






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-10-11 17:38:56 By : maxairzoom
 


 

No. 2



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



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


อ่อลืมดูอีกที่นึงขอโทดด้วยครับ
Code (PHP)
echo $_POST["hdnMaxLine"];

มาดูด้วยครับ เห็นค่าจาก Form เป็น 0 ถ้าค่ามันมา 0 for loob ที่ตั้งไว้มันจะไม่ทำงานนะครับ ลอง echo ดูว่าได้ค่าอะไรออกมา
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2012-10-11 17:42:57 By : maxairzoom
 

   

ค้นหาข้อมูล


   
 

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