ดู code หน่อยครับ EditUpdate Record พอจะกด EditUpdate Record data มันไม่เข้า mysql คับ ไม่มี err งง
1 file AjaxASPEditRecord1.asp
--------
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
<style type="text/css">
<!--
.style1 {color: #0000FF}
-->
</style>
</head>
<script language="JavaScript">
var HttPRequest = false;
function doCallAjax(Mode) {
HttPRequest = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
HttPRequest = new XMLHttpRequest();
if (HttPRequest.overrideMimeType) {
HttPRequest.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
HttPRequest = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
HttPRequest = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!HttPRequest) {
alert('Cannot create XMLHTTP instance');
return false;
}
var url = 'AjaxPHPEditRecord2.php';
if(Mode == "UPDATE")
{
var pmeters = "tid=" + encodeURI( document.getElementById("txtid").value) +
"&tname=" + encodeURI( document.getElementById("txtname").value ) +
"&tgroup=" + encodeURI( document.getElementById("txtgroup").value ) +
"&tdate=" + encodeURI( document.getElementById("txtdate").value ) +
"&tdate2=" + encodeURI( document.getElementById("txtdate2").value ) +
"&tdate3=" + encodeURI( document.getElementById("txtdate3").value ) +
"&ttime=" + encodeURI( document.getElementById("txttime").value ) +
"&ttime2=" + encodeURI( document.getElementById("txttime2").value ) +
"&tdetails=" + encodeURI( document.getElementById("txtdetails").value ) +
"&tstatus=" + encodeURI( document.getElementById("status").value ) +
"&tMode=" + Mode;
}
if(Mode == "LIST")
{
var pmeters = "";
}
HttPRequest.open('POST',url,true);
HttPRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
HttPRequest.setRequestHeader("Content-length", pmeters.length);
HttPRequest.setRequestHeader("Connection", "close");
HttPRequest.send(pmeters);
HttPRequest.onreadystatechange = function()
{
if(HttPRequest.readyState == 3) // Loading Request
{
document.getElementById("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById("myForm").style.display = 'none';
document.getElementById("txtid").value = '';
document.getElementById("txtname").value = '';
document.getElementById("txtgroup").value = '';
document.getElementById("txtdate").value = '';
document.getElementById("txtdate2").value = '';
document.getElementById("txtdate3").value = '';
document.getElementById("txttime").value = '';
document.getElementById("txttime2").value = '';
document.getElementById("txtdetails").value = '';
document.getElementById("status").value = '';
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
}
}
}
function ShowEdit(sid,sname,sgroup,sdate,sdate2,sdate3,stime,stime2,sdetails,sstatus)
{
document.getElementById("myForm").style.display = '';
document.getElementById("txtid").value = sid;
document.getElementById("txtname").value = sname;
document.getElementById("txtgroup").value = sgroup;
document.getElementById("txtdate").value = sdate;
document.getElementById("txtdate2").value = sdate2;
document.getElementById("txtdate3").value = sdate3;
document.getElementById("txttime").value = stime;
document.getElementById("txttime2").value = stime2;
document.getElementById("txtdetails").value = sdetails;
document.getElementById("status").value = sstatus;
}
</script>
<body Onload="JavaScript:doCallAjax('LIST');">
<h1 align="center" class="style1">Computer service online</h1>
<form name="frmMain">
<span id="myForm" style="display='none';">
<table width="1191" border="1">
<tr>
<th width="37"> <div align="center" class="style1">ID</div></th>
<th width="157"> <div align="center" class="style1">Name</div></th>
<th width="120"> <div align="center" class="style1">Group</div></th>
<th width="190"> <div align="center" class="style1">Date</div></th>
<th width="179"> <div align="center" class="style1">Time</div></th>
<th width="300"><div align="center" class="style1">Details</div></th>
<th width="162"><div align="center" class="style1">Status</div></th>
</tr>
<tr>
<td><div align="center">
<input type="text" name="txtid" id="txtid" size="5" disabled="true">
</div></td>
<td><div align="center">
<input type="text" name="txtname" id="txtname" size="20">
</div></td>
<td><div align="center">
<input type="text" name="txtgroup" id="txtgroup" size="20">
</div></td>
<td><div align="center">
<input type="text" name="txtdate" id="txtdate" size="1">
:
<input type="text" name="txtdate2" id="txtdate2" size="1">
:
<input type="text" name="txtdate3" id="txtdate3" size="2">
</div></td>
<td align="right"><div align="center">
<input type="text" name="txttime" id="txttime" size="1">
:
<input type="text" name="txttime2" id="txttime1" size="1">
</div></td>
<td align="right"><div align="center">
<input type="text" name="txtdetails" id="txtdetails" size="50">
</div></td>
<td align="right"><label>
<input type="text" name="status" id="status" />
</label>
<label>
<div align="center"></div>
</label></td>
</tr>
</table>
<input type="button" name="btnUpdate" id="btnUpdate" value="Update" OnClick="JavaScript:doCallAjax('UPDATE');">
<br><br></span>
<span id="mySpan"></span>
</form>
</body>
</html>
--------------------------------------------
2. file AjaxPHPEditRecord2.php
---------------------
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$strMode = $_POST["tMode"];
$objConnect = mysql_connect("localhost","root","999999")or die("Error Connect to Database");
$objDB = mysql_select_db("online");
if($strMode == "UPDATE")
{
$strSQL = "UPDATE form SET ";
$strSQL .="name = '".$_POST["tname"]."' ";
$strSQL .=",group = '".$_POST["tgroup"]."' ";
$strSQL .=",date = '".$_POST["tdate"]."' ";
$strSQL .=",date2 = '".$_POST["tdate2"]."' ";
$strSQL .=",date3= '".$_POST["tdate3"]."' ";
$strSQL .=",time= '".$_POST["ttime"]."' ";
$strSQL .=",time2= '".$_POST["ttime2"]."' ";
$strSQL .=",details = '".$_POST["tdetails"]."' ";
$strSQL .=",status = '".$_POST["tstatus"]."' ";
$strSQL .="WHERE id = '".$_POST["tid"]."' ";
$objQuery = mysql_query($strSQL);
}
$strSQL = "SELECT * FROM form WHERE name LIKE '%".$strSearch."%' ORDER BY id ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<style type="text/css">
<!--
.style2 {color: #0000FF}
.style3 {font-weight: bold; color: #0000FF; }
-->
</style>
<table width="1134" border="1">
<tr>
<th width="44"> <div align="center" class="style2">ID</div></th>
<th width="153"> <div align="center" class="style2">Name</div></th>
<th width="130"> <div align="center" class="style2">Group</div></th>
<th width="151"> <div align="center" class="style2">Date</div></th>
<th width="110"> <div align="center" class="style2">Time</div></th>
<th width="303"> <div align="center"><span class="style3">Details</span></div></th>
<th width="153"><div align="center"><span class="style3">Status</span></div></th>
<th width="38"> <div align="center" class="style2">Edit</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><div align="center">
<?=$objResult["id"];?>
</div></td>
<td><div align="center">
<?=$objResult["name"];?>
</div></td>
<td><div align="center">
<?=$objResult["group"];?>
</div></td>
<td><div align="center"><strong>
<?=$objResult["date"];?>
:
<?=$objResult["date2"];?>
:
<?=$objResult["date3"];?>
</strong></div></td>
<td align="right"><div align="center"><strong>
<?=$objResult["time"];?>
:
<?=$objResult["time2"];?>
</strong></div></td>
<td align="right"><div align="center">
<?=$objResult["details"];?>
</div></td>
<td align="center"><div align="center">
<?=$objResult["status"];?>
</div></td>
<td align="center"><div align="center"><a href="JavaScript:ShowEdit('<?=$objResult["id"];?>','<?=$objResult["name"];?>','<?=$objResult["group"];?>','<?=$objResult["date"];?>','<?=$objResult["date2"];?>','<?=$objResult["date3"];?>','<?=$objResult["time"];?>','<?=$objResult["time2"];?>','<?=$objResult["details"];?>','<?=$objResult["status"];?>')">Edit</a></div></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
---------------
sql
------------------
-- --------------------------------------------------------
--
-- Table structure for table `form`
--
CREATE TABLE IF NOT EXISTS `form` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(50) NOT NULL,
`group` varchar(50) NOT NULL,
`date` int(11) NOT NULL,
`date2` char(11) NOT NULL,
`date3` int(11) NOT NULL,
`time` char(11) NOT NULL,
`time2` char(11) NOT NULL,
`details` text NOT NULL,
`status` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=24 ;
--
-- Dumping data for table `form`
--
INSERT INTO `form` (`id`, `name`, `group`, `date`, `date2`, `date3`, `time`, `time2`, `details`, `status`) VALUES
(17, 'rrrrrr', 'rrrrrr', 31, 'Jan', 2010, '7', '00', 'dddddddddddddddd', ''),
(18, 'yyyyyyy', 'yyyyyyy', 2, 'May', 2010, '1', '59', 'dddddddddddddddd', ''),
(19, 'oooooo', 'oooooo', 25, 'Feb', 2010, '1', '09', 'dddddddddddddddd', ''),
(20, 'llll', 'lllll', 25, 'Feb', 2010, '19', '13', 'dddddddddddddddd', ''),
(22, 'it', 'it', 19, 'Jan', 2010, '14', '00', 'lan เสีย', 'รอการดำเนิดการ'),
(23, 'นานา', 'นา', 21, 'Mar', 2010, '13', '21', 'test', 'รอการดำเนิดการ');
---------------------------------------------
พี่น้องครับ ช่วยที่ครับ งงครับ
ไม่มี err พอกดแก้ไขข้อมูล data ไม่ยอมแก้ไขครับ
ขอบคูณครับพี่น้องTag : - - - -
Date :
2010-01-19 16:10:47
By :
care123
View :
809
Reply :
2
ที่ผมเคยเจอ อาการแบบนี้มักเกิดจาก name ของ text box กับ ชื่อ field ตอนที่ใส่คำสั่ง Insert ใน SQL ไม่ถูกต้อง เลยไม่มีการ Error แต่ข้อมูลไม่ลง Database ลองเช็คดูอีกทีครับ
Date :
2010-01-19 16:26:59
By :
krajib
ขอบคูณครับ
ดูตาลายแล้วครับไม่เจอเลยอะครับ
Date :
2010-01-19 16:34:20
By :
care123
Load balance : Server 05