|
|
|
รบกวนช่วยดู Code ให้ด้วยครับ ว่าผิดตรงไหน เนื่องจากหลังจาก UPDATE แล้วจะฟ้อง ERROR ดังรูปครับ |
|
|
|
|
|
|
|
CODE ที่ใช้ครับ
Code (PHP)
<?php
session_start();
if($_SESSION['user_id'] == "") {
header("location:index.php"); }
if($_SESSION['user_status'] != "esc")
{
echo "This page for User only!";
exit(); }
mysql_connect("localhost","root","root");
mysql_select_db("parttime");
mysql_query("SET NAMES UTF8");
$strSQL = "SELECT * FROM user WHERE user_id = '".$_SESSION['user_id']."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
?>
<?php require_once('Connections/parttime.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
$insertstartDate = date("Y-m-d",strtotime($startdate));
$insertendDate = date("Y-m-d",strtotime($enddate));
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "editdate")) {
$updateSQL = sprintf("UPDATE history SET dept=%s, startdate=%s, enddate=%s WHERE id=%s",
GetSQLValueString($_POST['dept'], "text"),
GetSQLValueString($insertstartDate, "date"),
GetSQLValueString($insertendDate, "date"),
GetSQLValueString($_POST['id'], "int"));
mysql_select_db($database_parttime, $parttime);
$Result1 = mysql_query($updateSQL, $parttime) or die(mysql_error());
$updateGoTo = "detail.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_editdate = "1";
if (isset($_GET['historyid'])) {
$colname_editdate = (get_magic_quotes_gpc()) ? $_GET['historyid'] : addslashes($_GET['historyid']);
}
mysql_select_db($database_parttime, $parttime);
mysql_query ("SET NAMES UTF8");
$query_editdate = sprintf("SELECT * FROM history WHERE id = %s", $colname_editdate);
$editdate = mysql_query($query_editdate, $parttime) or die(mysql_error());
$row_editdate = mysql_fetch_assoc($editdate);
$totalRows_editdate = mysql_num_rows($editdate);
?>
<?php
mysql_select_db($database_parttime, $parttime);
$query_name = "SELECT parttime.name, parttime.surname FROM history LEFT JOIN parttime ON history.pt_id = parttime.id WHERE history.pt_id='".$row_editdate['pt_id']."'";
$name = mysql_query($query_name, $parttime) or die(mysql_error());
$row_name = mysql_fetch_assoc($name);
$totalRows_name = mysql_num_rows($name);
mysql_select_db($database_parttime, $parttime);
$query_edit ="SELECT *,DATE_FORMAT(startdate,'%d %b %Y') AS startdate ,DATE_FORMAT(enddate,'%d %b %Y') AS enddate FROM history WHERE id = '".$row_editdate['id']."'";
$edit = mysql_query($query_edit, $parttime) or die(mysql_error());
$row_edit = mysql_fetch_assoc($edit);
$totalRows_edit = mysql_num_rows($edit);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>edit date</title>
<style type="text/css">
<!--
.style1 {font-weight: bold}
.style3 {color: #0000FF}
-->
</style>
</head>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr bgcolor="#FF0000">
<th height="41" scope="col">แก้ไขวันที่ทำงาน<span class="style5">ให้กับพนักงาน</span></th>
</tr>
<tr bgcolor="#FF0000">
<th height="41" bgcolor="#FFFFFF" scope="col"> </th>
</tr>
</table>
<form action="<?php echo $editFormAction; ?>" method="POST" name="editdate" id="editdate" onSubmit="MM_validateForm('location','','R','dept','','R','startdate','','R');return document.MM_returnValue">
<table width="90%" height="202" border="0" align="center" cellpadding="0" cellspacing="0">
<tr valign="middle" bgcolor="#FF0000">
<th height="30" colspan="5" scope="col"><div align="center"></div>
<div align="center" class="style5"></div> <div align="center"></div> <div align="center"></div></th>
</tr>
<tr bgcolor="#CCCCCC">
<th height="32" scope="col"><span class="style3">
</span></th>
<th align="left" scope="col">ชื่อ</th>
<th colspan="3" align="left" scope="col"><?php echo $row_name['name']; ?> </th>
</tr>
<tr bgcolor="#CCCCCC">
<th height="32" scope="col"> </th>
<th align="left" scope="col">นามสกุล</th>
<th colspan="3" align="left" scope="col"><?php echo $row_name['surname']; ?></th>
</tr>
<tr bgcolor="#CCCCCC">
<th width="11%" height="32" scope="col"> </th>
<th width="17%" align="left" scope="col"><span class="style19 style1 style4">สาขา</span></th>
<th colspan="3" align="left" scope="col"><?php echo $row_edit['location']; ?> </th>
</tr>
<tr bgcolor="#CCCCCC">
<td height="33"> </td>
<td><strong>ตำแหน่งงาน</strong></td>
<td width="33%"><input name="dept" type="text" id="dept" value="<?php echo $row_edit['dept']; ?>" size="30" maxlength="30" ></td>
<td colspan="2"><input type="hidden" name="user_id" id="user_id" value=<?=$objResult["user_id"];?>></td>
</tr>
<tr bgcolor="#CCCCCC">
<td height="33"> </td>
<td><span class="style19 style1 style4"><strong>จากวันที่</strong></span></td>
<td>
<link rel="stylesheet" type="text/css" href="css/black-tie/jquery-ui-1.9.1.custom.min.css">
<script src="css/js/jquery-1.8.2.js"></script>
<script src="css/js/jquery-ui-1.9.1.custom.js"></script>
<script src="development-bundle/ui/jquery.ui.datepicker.js"></script>
<script>
$(function() {
$( "#startdate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd M yy'
});
});
</script>
<style type="text/css">
.ui-datepicker{
width:180px;
font-family:tahoma;
font-size:11px;
text-align:center;
}
</style>
<input name="startdate" type="text" id="startdate" value="<?php echo $row_edit['startdate']; ?>">
</td>
<td colspan="2"><input type="text" name="id" id="id" value=<?php echo $row_edit['id']; ?>>
</tr>
<tr bgcolor="#CCCCCC">
<td height="34"> </td>
<td><span class="style19 style1 style4"><strong>ถึงวันที่</strong></span></td>
<td>
<link rel="stylesheet" type="text/css" href="css/black-tie/jquery-ui-1.9.1.custom.min.css">
<script src="css/js/jquery-1.8.2.js"></script>
<script src="css/js/jquery-ui-1.9.1.custom.js"></script>
<script src="development-bundle/ui/jquery.ui.datepicker.js"></script>
<script>
$(function() {
$( "#enddate" ).datepicker({
changeMonth: true,
changeYear: true,
dateFormat: 'dd M yy'
});
});
</script>
<style type="text/css">
.ui-datepicker{
width:180px;
font-family:tahoma;
font-size:11px;
text-align:center;
}
</style>
<input name="enddate" type="text" id="enddate" value="<?php echo $row_edit['enddate']; ?>"></td>
<td colspan="2"> </td>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="2"> </td>
<td><input type="submit" name="submit" value="ยืนยันการบันทึก"></td>
<td width="28%" colspan="2"><input type=button name=type value=' ยกเลิก ' onClick="setVisibility('show_demo', '')";></td>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="2"><input name="hiddenField" type="hidden" value="<?php echo $row_name['id']; ?>"></td>
<td> </td>
<td colspan="2"> </td>
</tr>
</table>
<input type="hidden" name="MM_update" value="editdate"> </form>
</body>
</html>
<?php
mysql_free_result($name);
mysql_free_result($edit);
mysql_free_result($editdate);
?>
Tag : PHP, JavaScript, jQuery
|
|
|
|
|
|
Date :
2012-11-13 09:45:50 |
By :
sranuwat |
View :
997 |
Reply :
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้โปรแกรมอะไรเขียนโค้ดครับ
ถ้าเป็น edit plus ตอนเซฟไฟล์ต้องเลือกเป็น UTF8
ถ้าเป็น notepad++ ต้องเป็น utf8 - without BOM
หลังจากนั้นให้ลบ <?php ในบรรทัดแรก ด้วยการกดปุ่ม "Backspace" เคาะซ้ำๆไปหลายๆที แล้วพิมพ์ <?php เข้าไปใหม่
|
|
|
|
|
Date :
2012-11-13 16:11:13 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมใช้ DREAMWAVER MX2004 ครับ
|
|
|
|
|
Date :
2012-11-13 16:24:14 |
By :
sranuwat |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองหา ดาวน์โหลดnotepad++ มาใช้แก้ไขโค้ดดูน่ะครับ แล้วทำตามที่ผมบอก
|
|
|
|
|
Date :
2012-11-13 16:31:42 |
By :
sakuraei |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ครับ ได้ครับ ขอบคุณมากครับ
|
|
|
|
|
Date :
2012-11-13 16:32:51 |
By :
sranuwat |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ใช้ Edit Plus ก็ได้ครับ
|
|
|
|
|
Date :
2012-11-14 09:14:20 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|