|
|
|
ข้อมูลสามารถบันทึกลงฐานข้อมูลได้แล้วแต่ไม่สามารถนำมาแสดงในตารางได้ |
|
|
|
|
|
|
|
ผมได้ทำตามตัวอย่างนี้ https://www.thaicreate.com/tutorial/ajax-add-insert-record.html แต่ติดปัญหาตรง Show data มันไม่ยอม Show แต่บันทึกได้ปกติ รบกวนผู้รู้ช่วยตรวจสอบให้หน่อยนะครับหาทางออกไม่เจอ
Code (PHP)
<?php
/*** By Weerachai Nukitram***/
/*** http://www.ThaiCreate.Com ***/
?>
<html>
<head>
<title>ThaiCreate.Com Ajax Tutorial</title>
</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 = 'inserttabletime.php';
var pMeters = "pTitle=" + encodeURI( document.getElementById("txtTitle").value) +
"&pBody=" + encodeURI( document.getElementById("txtBody").value ) +
"&pMode=" + 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("mySpan").innerHTML = "Now is Loading...";
}
if(HttPRequest.readyState == 4) // Return Request
{
document.getElementById("mySpan").innerHTML = HttPRequest.responseText;
document.getElementById("txtTitle").value = '';
document.getElementById("txtBody").value = '';
}
}
}
</script>
<body Onload="JavaScript:doCallAjax('LIST');">
<h1>My Customer</h1>
<form name="frmMain">
<table width="600" border="1">
<tr>
<th width="91"> <div align="center">Title</div></th>
<th width="98"> <div align="center">Body</div></th>
</tr>
<tr>
<td><input type="text" name="txtName" id="txtTitle" size="20"></td>
<td><input type="text" name="txtEmail" id="txtBody" size="20"></td>
</tr>
</table>
<input type="button" name="btnAdd" id="btnAdd" value="Add" OnClick="JavaScript:doCallAjax('ADD');">
<br><br>
<span id="mySpan"></span>
</form>
</body>
</html>
Code (PHP)
<?php
/*** By Weerachai Nukitram ***/
/*** http://www.ThaiCreate.Com ***/
$strMode = $_POST["pMode"];
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("1234");
if($strMode == "ADD")
{
$strSQL = "INSERT INTO schedule ";
$strSQL .="(title,body) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["pTitle"]."','".$_POST["pBody"]."') ";
$objQuery = mysql_query($strSQL);
}
$strSQL = "SELECT * FROM schedule WHERE title LIKE '%".$strSearch."%' ORDER BY title ASC ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<table border="1">
<tr>
<th width="91"> <div align="center">Title</div></th>
<th width="98"> <div align="center">Body</div></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
<tr>
<td><?=$objResult["Title"];?></td>
<td><?=$objResult["Body"];?></td>
</tr>
<?
}
?>
</table>
<?
mysql_close($objConnect);
?>
Tag : PHP
|
|
|
|
|
|
Date :
2011-04-22 16:45:44 |
By :
Agility |
View :
700 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$objDB = mysql_select_db("1234");ชื่อดาต้าเบส ไม่รู้ตรงกันหรือป่าว
แล้วเวลาแอดมันแอดลงด้านข้อมูลมั้ย
ลองไปดูนะคับ
|
|
|
|
|
Date :
2011-04-22 17:00:36 |
By :
deknoy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|