|
|
|
INSERT ผลรวมเข้าฐานข้อมูลไม่ได้ครับต้องทำยังไงหรือผมทำอะไรผิดไปช่วยดูให้ทีครับ |
|
|
|
|
|
|
|
หน้าที่ใช้กรอกครับ
Code (PHP)
<?
include "config.inc.php";
$con2 = mysql_connect($host,$username,$password);
$id_employee= $_GET["id_employee"];
if (!$con2)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db($database, $con2);
$result2 = mysql_query("SELECT * FROM employee_details WHERE id_employee=".$id_employee);
$row2 = mysql_fetch_array($result2);
$con3 = mysql_connect($host,$username,$password);
if (!$con3)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db($database, $con3);
$result3 = mysql_query("SELECT * FROM employee_salaot");
$row3 = mysql_fetch_array($result3);
?>
<link rel="stylesheet" media="all" type="text/css" href="js/jquerydatepicker/jquery-ui.css" />
<link rel="stylesheet" media="all" type="text/css" href="js/jquerydatepicker/jquery-ui-timepicker-addon.css" />
<script type="text/javascript" src="js/jquerydatepicker/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="js/jquerydatepicker/jquery-ui.min.js"></script>
<script type="text/javascript" src="js/jquerydatepicker/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript" src="js/jquerydatepicker/jquery-ui-sliderAccess.js"></script>
<script src="SpryAssets/SpryValidationSelect.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationSelect.css" rel="stylesheet" type="text/css" />
<form action="employ_insert_salaot.php" method="post" name="form1" id="form1">
<table width="200" border="1" align="center">
<tr>
<td>รหัสพนักงาน</td>
<td>ชื่อ-นามสกล</td>
<td>วันที่ทำโอที</td>
<td>ค่าโอที/ชั่วโมง</td>
<td>เวลาที่ทำโอที(ชั่วโมง)</td>
</tr>
<tr>
<td><?=$row2['id_employee']?></td>
<td><?=$row2['first_name']?>
<?=$row2['last_name']?></td>
<td id="startdate"><script type="text/javascript">
$(function(){
$("#date_ot").datepicker({
dateFormat: 'yy-mm-dd',
numberOfMonths: 1,
});
});
</script>
<input type="text" name="date_ot" id="date_ot" value="" /></td>
<td><?=$row3['sala_ot']?>
<input name="id_otsala" type="hidden" id="id_otsala" value="<?=$row3['id_otsala']?>" /></td>
<td><label for="label"></label>
<input name="hour_ot" type="text" id="hour_ot"></td>
</tr>
</table>
<input type="submit" name="button" id="button" value="Submit">
<input name="id_employee" type="hidden" id="id_employee" value="<?=$row2['id_employee']?>" />
<?
$hour_ot=$_POST[hour_ot];
$tot_ot=$row3['sala_ot']*$hour_ot;
?>
</form>
<?
mysql_close($con2);
mysql_close($con3);
?>
ส่วนที่หน้า insert ครับ
Code (PHP)
<?
include "config.inc.php";
$con = mysql_connect($host,$username,$password);
if (!$con)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db($database, $con);
mysql_query("SET NAMES UTF8");
$id_employee= $_POST["id_employee"];
$date_ot= $_POST["date_ot"];
$id_otsala= $_POST["id_otsala"];
$hour_ot= $_POST["hour_ot"];
$tot_ot= $_POST["tot_ot"];
$sql="INSERT INTO employee_totalot(id_otsala,date_ot,id_employee,hour_ot,tot_ot)
VALUES('$id_otsala','$date_ot','$id_employee','$hour_ot','$tot_ot')";
if (!mysql_query($sql,$con))
{ die('Error: ' . mysql_error()); }
header("Location: employee_detail_list.php");
mysql_close($con);
?>
Tag : PHP, MySQL
|
ประวัติการแก้ไข 2015-02-24 15:18:22
|
|
|
|
|
Date :
2015-02-24 15:16:58 |
By :
narongsad |
View :
731 |
Reply :
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หน้าที่ใช้กรอก
Code (PHP)
<tr>
<td><?=$row2['id_employee']?></td>
<td><?=$row2['first_name']?> <?=$row2['last_name']?></td>
<td id="startdate">
<script type="text/javascript">
$(function(){
$("#date_ot").datepicker({
dateFormat: 'yy-mm-dd',
numberOfMonths: 1,
});
});
</script>
<input type="text" name="date_ot" id="date_ot" value="" />
</td>
<td>
<?=$row3['sala_ot']?>
<input name="sala_ot" type="hidden" id="sala_ot" value="<?=$row3['sala_ot']?>" />
<input name="id_otsala" type="hidden" id="id_otsala" value="<?=$row3['id_otsala']?>" />
</td>
<td><label for="label"></label>
<input name="hour_ot" type="text" id="hour_ot">
</td>
</tr>
</table>
<input type="submit" name="button" id="button" value="Submit">
<input name="id_employee" type="hidden" id="id_employee" value="<?=$row2['id_employee']?>" />
<?
//$hour_ot=$_POST[hour_ot];
//$tot_ot=$row3['sala_ot']*$hour_ot;
?>
หน้า Insert
Code (PHP)
<?
include "config.inc.php";
$con = mysql_connect($host,$username,$password);
if (!$con)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db($database, $con);
mysql_query("SET NAMES UTF8");
$id_employee= $_POST["id_employee"];
$date_ot= $_POST["date_ot"];
$id_otsala= $_POST["id_otsala"];
$hour_ot= $_POST["hour_ot"];
$sala_ot= $_POST["sala_ot"];
$tot_ot = $sala_ot * $hour_ot;
$sql="INSERT INTO employee_totalot(id_otsala,date_ot,id_employee,hour_ot,tot_ot)
VALUES('$id_otsala','$date_ot','$id_employee','$hour_ot','$tot_ot')";
if (!mysql_query($sql,$con))
{ die('Error: ' . mysql_error()); }
header("Location: employee_detail_list.php");
mysql_close($con);
?>
|
ประวัติการแก้ไข 2015-02-24 16:05:58 2015-02-24 16:06:40
|
|
|
|
Date :
2015-02-24 15:52:06 |
By :
sabaitip |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หน้าที่ใช้กรอกเพิ่ม hidden นี้แล้วใช่ป่าว
Code (PHP)
<input name="sala_ot" type="hidden" id="sala_ot" value="<?=$row3['sala_ot']?>" />
ส่วนหน้า insert ใส่อันนี้ยัง
Code (PHP)
$id_employee= $_POST["id_employee"];
$date_ot= $_POST["date_ot"];
$id_otsala= $_POST["id_otsala"];
$hour_ot= $_POST["hour_ot"];
$sala_ot= $_POST["sala_ot"];
$tot_ot = $sala_ot * $hour_ot;
|
|
|
|
|
Date :
2015-02-24 16:19:32 |
By :
sabaitip |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|