|
|
|
ติดปัญหาเรื่องการบันทีกข้อมูล รบกวนช่วยแก้ปัญหาให้หน่อยครับ |
|
|
|
|
|
|
|
ติดตรงที่มันไม่ยอมบันทึกข้อมูลลงฐานข้อมูล ไม่ทราบว่าตรงปุ่ม Save ผมทำถูกไหมครับ
ปุ่ม Save มันมี css ควบคุมด้วยนะครับคิดว่าไม่เกี่ยวก็เลยไม่ได้ก็อบมานะครับ
Code
<!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" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>ทดสอบ X</title>
<link rel="stylesheet" href="general.css" type="text/css" media="screen">
<script src="jquery-1.2.6.min.js" type="text/javascript"></script>
<script src="popup.js" type="text/javascript"></script>
</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 = 'insert.php';
var pmeters = "p_schedule_date=" + encodeURI( document.getElementById("txtschedule_date").value) +
"&p_subject=" + encodeURI( document.getElementById("txtsubject").value ) +
"&p_detail=" + encodeURI( document.getElementById("txtdetail").value ) +
"&p_Mode=" + Mode;
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("myresult").innerHTML = "Now is Loading...";
}
if(HttpRequest.readyState == 4) // Return Request
{
document.getElementById("myresult").innerHTML = HttPRequest.responseText;
document.getElementById("txtschedule_date").value = '';
document.getElementById("txtsubject").value = '';
document.getElementById("txtdetail").value = '';
}
}
}
</script>
<body Onload="JavaScript:doCallAjax('LIST');">
<div id="button"><input type="submit" value="Show Popup!" /></div>
<div id="popupContact">
<a id="popupContactClose">x</a>
<h1>555</h1>
<p><label for ="schedule_date">Schedule Date :</label> <input type = "text" name = "txtschedule_date"></p>
<p><label for = "subject">Subject :</label> <input type="text" name="txtsubject"></p>
<p><label for = "detail">Detail:</label> <textarea name="txtdetail"> </textarea></p>
<div class="button_action">
<a href="JavaScript:doCallAjax('ADD');" id="save"> <img src="images/apply.png"> Save </a>
<a href="" id="cancel"> <img src="images/cross.png"> Cancel </a>
</div>
</div>
<div id="backgroundPopup"></div>
<span id = "myresult" />
</body>
</html>
Code (PHP)
<?php
$strMode = $_POST["p_Mode"];
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("DB1");
if($strMode == "ADD")
{
$strSQL = "INSERT INTO schedule ";
$strSQL .="(schedule_date,subject,detail) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["p_schedule_date"]."','".$_POST["p_subject"]."','".$_POST["p_detail"]."') ";
$objQuery = mysql_query($strSQL);
}
$strSQL = "SELECT * FROM schedule WHERE schedule_date LIKE '%".$strSearch."%' ORDER BY schedule_date ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">Schedule Date</div></th>
<th width="98"> <div align="center">Subject</div></th>
<th width="198"> <div align="center">Detail</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><?=$objResult["schedule_date"];?></td>
<td><?=$objResult["subject"];?></td>
<td><?=$objResult["detail"];?></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
Tag : PHP
|
|
|
|
|
|
Date :
2011-05-09 08:49:37 |
By :
Agility |
View :
684 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลอง echo $strSQL; ดูครับ ว่ามันได้เข้าทำงานใน Statement นี้หรือเปล่าครับ
Code (PHP)
if($strMode == "ADD")
{
$strSQL = "INSERT INTO schedule ";
$strSQL .="(schedule_date,subject,detail) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["p_schedule_date"]."','".$_POST["p_subject"]."','".$_POST["p_detail"]."') ";
echo $strSQL;
$objQuery = mysql_query($strSQL) or die(mysql_error());
}
|
|
|
|
|
Date :
2011-05-09 09:29:33 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|