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 > สอบถามเรื่อง ค้นหาข้อมูลจาก mysql โดยแสดงข้อมูลจาก textbox + submit ข้อมูลลงใน database



 

สอบถามเรื่อง ค้นหาข้อมูลจาก mysql โดยแสดงข้อมูลจาก textbox + submit ข้อมูลลงใน database

 



Topic : 115620



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



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




สวัสดีครับ
ผมต้องการเก็บข้อมูลพนักงานทำงาน
โดย
1:ค้นหาข้อมูลตามวันที่ มาแสดงใน textbox
2:ข้อมูลที่ไม่มีใน textbox > user สามารถเพิ่มข้อมูล
3: บันทึกทึกข้อมูล
3.1 ข้อมูลที่มีอยู่แล้ว = update
3.2 ข้อมูลใหม่ = insert

พอจะมีตัวอย่างมั้ยครับ
ตอนนี้ผมทำ 2 form แต่ส่งค่าไม่ไปอ่าาา


Form

ขอบคุณล่วงหน้าครับ

Code (PHP)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Hellomyweb.com</title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<?php require_once('Connection/conn.php'); ?>


<style type="text/css">
<!--
#head {
	background-image: url(images/head.jpg);
	background-repeat: no-repeat;
	clear: both;
	height: 150px;
	width: 796px;
	border: 2px solid #FFFFFF;
}
-->
</style>
</head>

<body>
<link rel="stylesheet" type="text/css" href="tcal.css" />
<script type="text/javascript" src="tcal.js"></script> 

<SCRIPT Language="JavaScript">

function startCalc(){ 
interval = setInterval("calc()",1); 
} 
function calc(){ 
	EmpDay = document.frmEmpInput.txtEmpDay.value; 
	EmpNight = document.frmEmpInput.txtEmpNight.value; 
	EmpNormalDay = document.frmEmpInput.EmpNormalDay.value; 
	EmpNormalNight = document.frmEmpInput.EmpNormalNight.value; 
	EmpPregDay= document.frmEmpInput.EmpPregDay.value; 
	EmpPregNight= document.frmEmpInput.EmpPregNight.value; 
	EmpActDay= document.frmEmpInput.EmpActDay.value; 
	EmpActNight= document.frmEmpInput.EmpActNight.value; 
	iEmpHolDay= document.frmEmpInput.EmpHolDay.value; 
	iEmpHolNight= document.frmEmpInput.EmpHolNight.value; 
	EmpSickDay= document.frmEmpInput.EmpSickDay.value; 
	EmpSickNight= document.frmEmpInput.EmpSickNight.value; 
	EmpSplDay= document.frmEmpInput.EmpSplDay.value; 
	EmpSplNight= document.frmEmpInput.EmpSplNight.value; 
	EmpAbsDay= document.frmEmpInput.EmpAbsDay.value; 
	EmpAbsNight= document.frmEmpInput.EmpAbsNight.value; 
	EmpMtlDay= document.frmEmpInput.EmpMtlDay.value; 
	EmpMtlNight= document.frmEmpInput.EmpMtlNight.value; 
	
	document.frmEmpInput.txtEmpAll.value = (EmpDay*1)+(EmpNight*1) ; 
	document.frmEmpInput.EmpNormalAll.value = (EmpNormalDay*1)+(EmpNormalNight*1) ; 
	document.frmEmpInput.EmpPregAll.value = (EmpPregDay*1)+(EmpPregNight*1) ; 

	
	document.frmEmpInput.EmpHolAll.value = (iEmpHolDay*1)+(iEmpHolNight*1) ; 
	document.frmEmpInput.EmpSickAll.value = (EmpSickDay*1)+(EmpSickNight*1) ; 
	document.frmEmpInput.EmpSplAll.value = (EmpSplDay*1)+(EmpSplNight*1) ; 
	document.frmEmpInput.EmpAbsAll.value = (EmpAbsDay*1)+(EmpAbsNight*1) ; 
	document.frmEmpInput.EmpMtlAll.value = (EmpMtlDay*1)+(EmpMtlNight*1) ; 
	
	document.frmEmpInput.EmpActDay.value = (EmpDay*1)-(iEmpHolDay*1)-(EmpSickDay*1)-(EmpAbsDay*1) -(EmpMtlDay*1); 
	document.frmEmpInput.EmpActNight.value = (EmpNight*1)-(iEmpHolNight*1)-(EmpSickNight*1)-(EmpAbsNight*1) -(EmpMtlNight*1) ; 
	document.frmEmpInput.EmpAct.value =(EmpDay*1)+(EmpNight*1)-(iEmpHolDay*1)-(iEmpHolNight*1) -(EmpSickDay*1)-(EmpSickNight*1)-(EmpAbsDay*1)-(EmpAbsNight*1)-(EmpMtlDay*1)-(EmpMtlNight*1) ;
	
	EmpActualDay=document.frmEmpInput.EmpActDay.value
	EmpActualNight=document.frmEmpInput.EmpActNight.value
	EmpActualAll=document.frmEmpInput.EmpAct.value
	//Cal percent emp
	document.frmEmpInput.EmpPerDay.value= (EmpActualDay*1)/((EmpDay*1)+(EmpNight*1));
	document.frmEmpInput.EmpPerNight.value= (EmpActualNight*1)/((EmpDay*1)+(EmpNight*1));
	document.frmEmpInput.EmpPer.value= (EmpActualAll*1)/((EmpDay*1)+(EmpNight*1));
} 

</SCRIPT>


<div align="center">

<div id="containner">

<div id="main">

<div id="right" align="center">
  <!-- end content-->
  <!-- end content-->
  <!-- end content-->
<div id="content" class="blue">
<h1>บันทึกอัตราการมาทำงาน</h1>
<div id="story">
  <form action="" method="post" name="frmEmpInput" id="frmEmpInput" >
  
  <script language="JavaScript">
document.onkeydown = chkEvent 
	function chkEvent(e) {
		var keycode;
		if (window.event) keycode = window.event.keyCode; //*** for IE ***//
		else if (e) keycode = e.which; //*** for Firefox ***//
		if(keycode==13)
		{
			return false;
		}
	}

    function setNextFocus(objId){
        if (event.keyCode == 13){
            var obj=document.getElementById(objId);
            if (obj){
                obj.focus();
            }
        }
    }

$(function(){
	$("#dateInput").datepicker({
	dateFormat: 'dd/M/yy'
	});
});

function showResult(result)
{
	if(result==1)
		{
			document.getElementById("divResult").innerHTML = "<font color=green> Save successfully! </font>  <br>";
		}
	elseif (result==2)
		{
			document.getElementById("divResult").innerHTML = "<font color=red> Error!! Cannot save data </font> <br>";
		}
	else
		{
			document.getElementById("divResult").innerHTML = "<font color=red> Error!! Cannot save data Tray again</font> <br>";
		}
}
</script>
<?php echo $result; ?>
    <table width="517" border="1">
      <tr>
        <td width="101">USER</td>
        <td colspan="3"><input name="txtusername" type="text" id="txtusername" value="XXX"></td>
        </tr>
      <tr>
        <td>SECTION</td>
        <td width="176"><input name="txtsection" type="text" id="txtsection" value="XXX"></td>
        <td width="79">FACTORY</td>
        <td width="127"><input name="txtfactory" type="text" id="txtfactory" value="XX"></td>
      </tr>
      <tr>
        <td>TYPE</td>
        <td colspan="3"><input name="txtclass" type="text" id="txtclass" value="NORMAL"></td>
        </tr>
    </table>
	
    <table width="455" border="1" cellspacing="0" bordercolor="#000000">
      <caption>
	  <br>
       <input name="txtdate" type="text" class="tcal" id="txtdate" value="<?=date('Y-m-d')?>">       
       <input name="btSearch" type="submit" id="btSearch" value="Search" >
       <br>
      </caption>
      <tr>
        <td width="91">&nbsp;</td>
        <td width="105">DAY SHIFT </td>
        <td width="6">&nbsp;	</td>
        <td width="105">NIGHT SHIFT</td>
        <td width="6">&nbsp;</td>
        <td width="105">TOTAL</td>
        <td width="7">&nbsp;</td>
        </tr>
<?php
	if($_POST["btSearch"]=="Search"){
		//############################## Check data in mas_empworkresult ###################################
		mysql_select_db($dbname,$IT) or die ("เชื่อมต่อฐานข้อมูลไม่ได้");
		$SectionCD='PC PO';
		$workdate = $_POST['date'];
		$strSQL =  "SELECT ";
		$strSQL .=  "sum(case when `EmpShift`='DAY' then `EmpFlg` else 0 end) as empday,  ";
		$strSQL .=  "sum(case when `EmpShift`='NIGHT' then `EmpFlg` else 0 end) as empnight  ";
		$strSQL .=  "FROM mas_emp ";
		$strSQL .=  "WHERE EmpFlg=1 " ;
		$strSQL .=  "and SectionCode='PC PO' ";
		$strSQL .=  "and FactoryCD = 'F1' "; 
	
		$result = mysql_query($strSQL, $IT) or die(mysql_error());
		$irow = mysql_fetch_array($result);
	}
	
?>
      <tr>
        <td>พนักงาน</td>
        <td><input name="txtEmpDay" type="text" id="txtEmpDay" size="5" value="<?php echo $irow["empday"];?>" onKeyUp="if(this.value*1!=this.value) this.value='' ;"  onFocus="startCalc();" onBlur="stopCalc();"></td>
        <td>&nbsp;</td>
        <td><input name="txtEmpNight" type="text" id="txtEmpNight" size="5" value="<?php echo $irow["empnight"];?>" onKeyUp="if(this.value*1!=this.value) this.value='' ;"  onFocus="startCalc();" onBlur="stopCalc();"></td>
        <td>&nbsp;</td>
        <td><input name="txtEmpAll" type="text" id="inputtxtbox"  size="5" readonly=""  ></td>
        <td>&nbsp;</td>
        </tr>
      <tr>
        <td>ปกติ</td>
        <td><input name="EmpNormalDay" type="text" id="inputtxtbox" value="0" size="5"  onKeyUp="if(this.value*1!=this.value) this.value='' ;"  onFocus="startCalc();" onBlur="stopCalc();"  onKeyDown="setNextFocus('EmpNormalNight');" readonly=""></td>
        <td>&nbsp;</td>
        <td><input name="EmpNormalNight" type="text" id="inputtxtbox" value="0" size="5" onKeyUp="if(this.value*1!=this.value) this.value='' ;"  onFocus="startCalc();" onBlur="stopCalc();" onKeyDown="setNextFocus('EmpPregDay');" readonly=""></td>
        <td>&nbsp;</td>
        <td><input name="EmpNormalAll" type="text" id="inputtxtbox" size="5" readonly="" ></td>
        <td>&nbsp;</td>
        </tr>
      <tr>
        <td>ทำงานจริง</td>
        <td><input name="EmpActDay" type="text" id="inputtxtbox"  onFocus="startCalc();" onBlur="stopCalc();" onKeyUp="if(this.value*1!=this.value) this.value='' ;" value="0" size="5"></td>
        <td>&nbsp;</td>
        <td><input name="EmpActNight" type="text" id="inputtxtbox"  onFocus="startCalc();" onBlur="stopCalc();" onKeyUp="if(this.value*1!=this.value) this.value='' ;" value="0" size="5"></td>
        <td>&nbsp;</td>
        <td><input name="EmpAct" type="text" id="inputtxtbox" size="5" readonly="" ></td>
        <td>&nbsp;</td>
        </tr>
      <tr>
        <td>ลากิจ</td>
        <td><input name="EmpSplDay" type="text" id="EmpSplDay"  onFocus="startCalc();" onBlur="stopCalc();" onKeyUp="if(this.value*1!=this.value) this.value='' ;" value="0" size="5" onKeyDown="setNextFocus('EmpSplNight');"></td>
        <td>&nbsp;</td>
        <td><input name="EmpSplNight" type="text" id="EmpSplNight"  onFocus="startCalc();" onBlur="stopCalc();" onKeyUp="if(this.value*1!=this.value) this.value='' ;" value="0" size="5" onKeyDown="setNextFocus('EmpAbsDay');"></td>
        <td>&nbsp;</td>
        <td><input name="EmpSplAll" type="text" id="inputtxtbox" size="5" readonly="" ></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>ขาดงาน</td>
        <td><input name="EmpAbsDay" type="text" id="EmpAbsDay"  onFocus="startCalc();" onBlur="stopCalc();" onKeyUp="if(this.value*1!=this.value) this.value='' ;" value="0" size="5" onKeyDown="setNextFocus('EmpAbsNight');"></td>
        <td>&nbsp;</td>
        <td><input name="EmpAbsNight" type="text" id="EmpAbsNight"  onFocus="startCalc();" onBlur="stopCalc();" onKeyUp="if(this.value*1!=this.value) this.value='' ;" value="0" size="5" onKeyDown="setNextFocus('EmpMtlDay');"></td>
        <td>&nbsp;</td>
        <td><input name="EmpAbsAll" type="text" id="inputtxtbox" size="5" readonly="" ></td>
        <td>&nbsp;</td>
        </tr>
      <tr>
        <td>%ทำงาน</td>
        <td><input name="EmpPerDay" type="text" id="inputtxtbox" size="5" readonly="" ></td>
        <td>&nbsp;</td>
        <td><input name="EmpPerNight" type="text" id="inputtxtbox" size="5" readonly="" ></td>
        <td>&nbsp;</td>
        <td><input name="EmpPer" type="text" id="inputtxtbox" size="5" readonly="" ></td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td colspan="5"><div align="center">
        </div></td>
        <td>&nbsp;</td>
        </tr>
    </table>

    <p>&nbsp;    </p>
  </form>

   </div>
<form action="InputEmpDailySave.php" method="post" name="frmEmpAccept" id="frmEmpAccept" target="iframe_target">
<iframe id="iframe_target" name="iframe_target" src="#" style="width:200;height:50;border:0px solid #fff;"></iframe>
<div id="divResult"></div>
    <input type="submit" name="Submit" value="Submit">
    <input type="submit" name="Submit" value="Clear">
</form>
<p id="auther">&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</div>
<!-- end content-->


 
</div> 
<!-- end right-->

</div> <!-- end main-->

</div> <!-- end containner -->


</div>
<?

	//}
	
	mysql_close();
?>
</body>
</html>







Tag : PHP









ประวัติการแก้ไข
2015-04-04 16:14:45
2015-04-04 16:15:25
2015-04-04 16:24:32
2015-04-04 16:26:14
2015-04-04 16:26:52
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-04-04 16:12:39 By : ืีnushiro View : 1030 Reply : 1
 

 

No. 1



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



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

https://www.thaicreate.com/php/php-mysql-mysqli-edit-update.html






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2020-06-03 17:10:37 By : PhrayaDev
 

   

ค้นหาข้อมูล


   
 

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