 |
พอดีกำลังศึกษาการทำ Insert in to การเพิ่มข้อมูลจากฟอร์มรับค่าไปยังฐานข้อมูลค่ะแต่ติดอยู่ที่ Error saveค่ะ |
|
 |
|
|
 |
 |
|
[Code (JavaScript)
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("tsmlib_db");
$strSQL = "INSERT INTO member";
$strSQL .="(memberid,firstname,surename,Status,birthday,IdentificationNumber,address,Email,phoneNumber,Dateregistered,expirationdate)";
$strSQL .= "VALUES";
$strSQL .="('".$_POST["txtmemberID"]."','".$_POST["txtfirstName"]."','".$_POST["txtsurname"]."','".$_POST["txtstetus"]."' ";
$strSQL .=",'".$_POST["txtbirtday"]."','".$_POST["txtIdentificationNumber"]."','".$_POST["txtaddress"]."','".$_POST["txtEmail"]."' ";
$strSQL .=",'".$_POST["txtdate"]."' ,'".$_POST["txtexpirationdate"]."')";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
ผลออกมาเป็นแบบนี้ค่ะ
Error Save [INSERT INTO member(memberid,firstname,surename,Status,birthday,IdentificationNumber,address,Email,phoneNumber,Dateregistered,expirationdate)VALUES('','','','' ,'','','','' ,'' ,'')]
Tag : PHP
|
ประวัติการแก้ไข 2014-08-19 12:47:52
|
 |
 |
 |
 |
Date :
2014-08-19 12:39:20 |
By :
ployjit |
View :
700 |
Reply :
9 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
17.echo "Error Save [".$strSQL."]" , "<br/>\n" , mysql_error(); // จะได้รู้ว่า error อะไรครับ
|
ประวัติการแก้ไข 2014-08-19 12:47:48
 |
 |
 |
 |
Date :
2014-08-19 12:42:14 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$strSQL = "INSERT INTO member";
$strSQL .="(
memberid
,firstname
,surename
,Status
,birthday
,IdentificationNumber
,address
,Email
,phoneNumber
,Dateregistered
,expirationdate)";
$strSQL .= "VALUES";
$strSQL .="(
'".$_POST["txtmemberID"]."'
,'".$_POST["txtfirstName"]."'
,'".$_POST["txtsurname"]."'
,'".$_POST["txtstetus"]."'
,'".$_POST["txtbirtday"]."'
,'".$_POST["txtIdentificationNumber"]."'
,'".$_POST["txtaddress"]."'
,'".$_POST["txtEmail"]."'
,'".$_POST["txtdate"]."'
,'".$_POST["txtexpirationdate"]."'
)";
แยกออกมาแล้ว ได้ field 11 fields แต่ใส่ค่าแค่ 10 fields มันไม่ match กันครับ เลยเกิด error
|
 |
 |
 |
 |
Date :
2014-08-19 12:46:10 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะ จะลองแก้ไขดูนะค่ะ 
|
 |
 |
 |
 |
Date :
2014-08-19 12:50:10 |
By :
ployjit |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำให้ครบ11ตัวแล้วค่ะแต่ก็ยังขึ้นเหมือนเดิม
Error Save [INSERT INTO member(memberid,firstname,surename,Status,birthday,IdentificationNumber,address,Email,phoneNumber,Dateregistered,expirationdate)VALUES('','','','' ,'','','','' ,'' ,'','')]
Code (JavaScript)
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("tsmlib_db");
$strSQL = "INSERT INTO member";
$strSQL .="(memberid,firstname,surename,Status,birthday,IdentificationNumber,address,Email,phoneNumber,Dateregistered,expirationdate)";
$strSQL .= "VALUES";
$strSQL .="('".$_POST["txtmemberid"]."','".$_POST["txtfirstname"]."','".$_POST["txtsurname"]."','".$_POST["txtstetus"]."' " ;
$strSQL .=",'".$_POST["txtbirtday"]."','".$_POST["txtIdentificationNumber"]."','".$_POST["txtaddress"]."','".$_POST["txtEmail"]."' " ;
$strSQL .=",'".$_POST["txtphonenumber"]."' ,'".$_POST["txtDateregisterd"]."','".$_POST["txtexpirationdate"]."')";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2014-08-19 14:45:13 |
By :
ployjit |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ทำไมค่ามัน ว่างหมดอะครับ
ลองแก้บรรทัดที่ 18. $objQuery = mysql_query($strSQL) or die(mysql_error());
|
 |
 |
 |
 |
Date :
2014-08-19 14:49:02 |
By :
Manussawin |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองทำแล้วค่ะ ผลได้เป็นแบบนี้ค่ะ
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id,firstname,surename,Status,birthday,IdentificationNumber,address,Email,phoneNu' at line 1
Code (PHP)
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("tsmlib_db");
$strSQL = "INSERT INTO member";
$strSQL .="(member id,firstname,surename,Status,birthday,IdentificationNumber,address,Email,phoneNumber,Dateregistered,expirationdate)";
$strSQL .= "VALUES";
$strSQL .="('".$_POST["txtmember id"]."','".$_POST["txtfirstname"]."','".$_POST["txtsurname"]."','".$_POST["txtstetus"]."' " ;
$strSQL .=",'".$_POST["txtbirtday"]."','".$_POST["txtIdentificationNumber"]."','".$_POST["txtaddress"]."','".$_POST["txtEmail"]."' " ;
$strSQL .=",'".$_POST["txtphonenumber"]."' ,'".$_POST["txtDateregisterd"]."','".$_POST["txtexpirationdate"]."')";
$objQuery = mysql_query($strSQL) or die(mysql_error());
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]" , "<br/>\n" , mysql_error();
}
mysql_close($objConnect);
?>
|
ประวัติการแก้ไข 2014-08-19 15:00:50 2014-08-19 15:01:40
 |
 |
 |
 |
Date :
2014-08-19 14:54:52 |
By :
ployjit |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้เราใช้ตัวนี้ศึกษาการทำฐานข้อมูลอยู่ค่ะ
Apache Web Server Version 2.2.8
PHP Script Language Version 5.2.6
MySQL Database Version 5.0.51b
phpMyAdmin Database Manager Version 2.10.3
|
 |
 |
 |
 |
Date :
2014-08-19 14:59:24 |
By :
ployjit |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
$strSQL .="(member id,firstname,surename,Status,birthd
surename sure name -> sure naka. 
ขอดู DB หน่อยค่ะ
|
 |
 |
 |
 |
Date :
2014-08-19 15:05:41 |
By :
LuckyStar |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ตอนนี้ทางเราแก้โค๊ดได้แล้วค่ะ ขอบคุณทุกคนมากนะค่ะ
ที่ช่วยดูและช่วยแก้ไขให้เรา
ขอบคุณมากค่ะ 
|
 |
 |
 |
 |
Date :
2014-08-19 15:50:06 |
By :
ployjit |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|