มีปัญหาติด error อย่างนี้อะครับ รบกวนช่วยดูให้ทีครับ
Fatal error: Uncaught exception 'com_exception' with message '<b>Source:</b> Microsoft OLE DB Provider for ODBC Drivers<br/><b>Description:</b> [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.' in C:\AppServ\www\My_NewProject\saveuser.php:18 Stack trace: #0 C:\AppServ\www\My_NewProject\saveuser.php(18): com->Open('INSERT INTO Use...', Object(com), 1, 3) #1 {main} thrown in C:\AppServ\www\My_NewProject\saveuser.php on line 18
ข้างบนนี่เป็นตัวอย่าง error อะครับ
ผมใช้ MS Access เป็น DB นะครับ โดยรันบน Appserv
Add_User.php
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {font-size: 36px}
.style2 {
font-size: 18px;
color: #FFFFFF;
}
-->
</style>
</head>
<body>
<form action="saveuser.php" method="post">
<table width="80%" border="0" align="center">
<tr>
<th height="53" colspan="4" bgcolor="#BDCCD4" scope="row"><span class="style2">User Information</span></th>
</tr>
<tr>
<th height="29" colspan="4" scope="row"> </th>
</tr>
<tr>
<th width="21%" scope="row"><div align="left">Personal No.</div></th>
<td width="4%"> </td>
<td colspan="2">
<input name="Personal_No" type="text" id="Personal_No" value="" size="50" />
</td>
</tr>
<tr>
<th scope="row"><div align="left">Function Code</div></th>
<td> </td>
<td colspan="2"><span class="style1">
<input name="Function_Code" type="text" id="Function_Code" value="" size="50" />
</span></td>
</tr>
<tr>
<th scope="row"><div align="left">Chargeback No.</div></th>
<td> </td>
<td colspan="2"><span class="style1">
<input name="Chargeback_No" type="text" id="Chargeback_No" value="" size="50" />
</span></td>
</tr>
<tr>
<th scope="row"><div align="left">Firstname</div></th>
<td> </td>
<td colspan="2"><span class="style1">
<input name="Firstname" type="text" id="Firstname" value="" size="50" />
</span></td>
</tr>
<tr>
<th scope="row"><div align="left">Lastname</div></th>
<td> </td>
<td colspan="2"><span class="style1">
<input name="Lastname" type="text" id="Lastname" value="" size="50" />
</span></td>
</tr>
<tr>
<th scope="row"><div align="left">User Location</div></th>
<td> </td>
<td colspan="2"><span class="style1">
<textarea name="User_Location" cols="50" id="User_Location"></textarea>
</span></td>
</tr>
<tr>
<th scope="row"><div align="left">Services</div></th>
<td> </td>
<td colspan="2"><span class="style1">
<textarea name="Services" cols="50" id="Services"></textarea>
</span></td>
</tr>
<tr>
<th scope="row"><div align="left">Ext.</div></th>
<td> </td>
<td colspan="2" align="center"><div align="left"><span class="style1">
<input name="Ext" type="text" id="Ext" value="" size="50" />
</span></div></td>
</tr>
<tr>
<th colspan="4" scope="row"> </th>
</tr>
<tr>
<th scope="row"> </th>
<td> </td>
<td width="18%" align="center">
<div align="center">
<input type="submit" name="submit" id="submit" value="Submit" />
</div></td><td width="57%" align="center"><div align="left">
<input type="reset" name="cancel" id="cancel" value="Cancel" />
</div></td>
</tr>
</table>
</form>
</body>
</html>
connect.php
$db = "DB/MyDB.mdb" ; //ชื่อฐานข้อมูล MsAccess
$msaccdb = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath($db);
$conn = new COM("ADODB.Connection") or die("Cannot start ADO");
$Rec = new COM("ADODB.Recordset");
saveuser.php
ob_start();
$Personal_No = $_POST["Personal_No"];
$Function_Code = $_POST["Function_Code"];
$Chargeback_No = $_POST["Chargeback_No"];
$Firstname = $_POST["Firstname"];
$Lastname = $_POST["Lastname"];
$User_Location = $_POST["User_Location"];
$Services = $_POST["Services"];
$Ext = $_POST["Ext"];
include "connect.php";
$str = "INSERT INTO User Information(Personal_No,Function_Code,Chargeback_No,Firstname,Lastname,User_Location,Services,Ext)
VALUES('$Personal_No','$Function_Code','$Chargeback_No','$Firstname','$Lastname','$User_Location','$Services','$Ext')";
$conn -> open($msaccdb);
$Rec->Open($str, $conn, 1, 3);
$Rec->Close();
$conn->close();
Tag : PHP, Ms Access, JavaScript, Ajax, jQuery
ประวัติการแก้ไข 2011-11-17 10:17:30
Date :
2011-11-17 09:43:21
By :
sebreshark
View :
708
Reply :
1
error ใน saveuser.php
statement sql insert นะครับ
INSERT INTO User Information >> ลองเปลี่ยนชื่อ Table เป็น User_Information หรือถ้าต้องการตั้งชื่อ Table ที่มี space ให้ใส่ square brackets ครอบด้วยนะครับ
[ User Information]
ประวัติการแก้ไข 2011-11-17 11:09:49
Date :
2011-11-17 11:09:01
By :
vbCrazy
Load balance : Server 03