 |
ช่วยเขียนโค๊ดเป็นตัวอย่างให้ทีครับ ลองเขียน ลองแก้ มาหลายครั้งไม่ได้ซักที ช่วยทีครับท่านผู้รู้ทั้งหลาย |
|
 |
|
|
 |
 |
|

ช่วยเขียนโค๊ดให้ทีครับ ผมลองหลายครั้งแล้วไม่ได้ซักที เกี่ยวกับการแทรก ข้อมูล และ บันทึก ข้อมูลเพิ่มเติมอะครับ
ช่วยที ผมลองเขียนแล้วมันเป็นแบบนี้ตลอดเลย ไม่สามารถบันทึกลง ดาต้าเบสได้ แก้หลายครั้งก็ไม่ได้ซักที รบกวน เขียนให้หน่อยครับ
อยากทาบว่า มันต้องแก้ไขตรงไหน
ไม่สามารถบันทึกได้ครับ [INSERT INTO datacar (idcar,car_name,model,type,coler, piston,horsepower,engine_number,vehicle_numbers, battery,volt,wheel,front_wheel,rear_wheel,type_rubber,width,long,high,weight,Load,factory, year,product_country,purchased_from,contract_number,price,type_oil,capacity) VALUES ('111','111','111' ,'111','111','111' ,'1111','111','111' ,'11','11','11' ,'11','111','11' ,'11','111','111' ,'111','111','1111' ,'111','111',' 111' ,'2222222','diesel','200' )]
ลองใส่เพิ่ม $objQuery = mysql_query($strSQL) or die mysql_error(); มันฟ้อง Query empty
ไม่รู้จะแก้ไงแล้ว ช่วยเขียนเป็นแนวทางให้ทีครับ
Tag : PHP
|
|
 |
 |
 |
 |
Date :
2012-02-07 18:40:40 |
By :
preacher |
View :
1139 |
Reply :
11 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองดูดีีครับ คุณ กำหนดค่าที่จะ insert ไป 28 ตัว แต่ data ที่ส่งให่ มีแค่ 27 ตัว insert ยังไงก็ไม่เข้าครับ อ๋อ อีกอย่างครับ เห็นมี idcar ไม่ทราบว่าตั้งเป็ Auto Increment หรือป่าวครับ ถ้าเป็น ก็ไม่ต้องกำหนดค่าให้มันครับ ลองครับ 
|
 |
 |
 |
 |
Date :
2012-02-07 18:49:14 |
By :
slurpee55555 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ได้ตั้งเป็น Auto Increment เพราะ idcar คือหมายเลขทะเบียนของรถอะครับ ไม่แน่ใจว่าต้องใช้ Auto Increment เลยไม่ได้กำหนดไว้
|
 |
 |
 |
 |
Date :
2012-02-07 18:58:48 |
By :
preacher |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
งั้นก็ใส่ค่าให้ครบครับ
|
 |
 |
 |
 |
Date :
2012-02-07 19:06:03 |
By :
slurpee55555 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
นี่โค๊ดครับ เปลี่ยน coler เป็น color แล้วนะครับ ชื่อ ฐาน car1 ชื่อตาราง datacar
<html>
<head>
<title>ARTILLERY CAR ADDSAVE</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","") or die("ไม่สามารถติดต่อฐานข้อมูลได้ครับ");
$objDB = mysql_select_db("car1");
$strSQL = "INSERT INTO datacar ";
$strSQL .="(idcar,car_name,model,type,color,piston,horsepower,engine_number,vehicle_numbers,battery,volt,wheel,front_wheel,rear_wheel,type_rubber,width,long,high,weight,Load,factory,year,product_country,purchased_from,contract_number,price,type_oil,capacity) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtidcar"]."','".$_POST["txtcar_name"]."','".$_POST["txtmodel"]."' ";
$strSQL .=",'".$_POST["txttype"]."','".$_POST["txtcolor"]."','".$_POST["txtpiston"]."' ";
$strSQL .=",'".$_POST["txthorsepower"]."','".$_POST["txtengine_number"]."','".$_POST["txtvehicle_numbers"]."' ";
$strSQL .=",'".$_POST["txtbattery"]."','".$_POST["txtvolt"]."','".$_POST["txtwheel"]."' ";
$strSQL .=",'".$_POST["txtfront_wheel"]."','".$_POST["txtrear_wheel"]."','".$_POST["txttype_rubber"]."' ";
$strSQL .=",'".$_POST["txtwidth"]."','".$_POST["txtlong"]."','".$_POST["txthigh"]."' ";
$strSQL .=",'".$_POST["txtweight"]."','".$_POST["txtLoad"]."','".$_POST["txtfactory"]."' ";
$strSQL .=",'".$_POST["txtyear"]."','".$_POST["txtproduct_country"]."','".$_POST["txtpurchased_from"]."' ";
$strSQL .=",'".$_POST["txtcontract_number"]."','".$_POST["txtprice"]."','".$_POST["txttype_oil"]."','".$_POST["txtcapacity"]."')";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "บันทึกเรียบร้อยแล้วครับ";
}
else
{
echo "ไม่สามารถบันทึกได้ครับ [".$strSQL."]";
}
mysql_close($objConnect);
?>
</body>
</html>
ผลออกมาแบบเดิม ครับ
ไม่สามารถบันทึกได้ครับ [INSERT INTO datacar (idcar,car_name,model,type,color,piston,horsepower,engine_number,vehicle_numbers,battery,volt,wheel,front_wheel,rear_wheel,type_rubber,width,long,high,weight,Load,factory,year,product_country,purchased_from,contract_number,price,type_oil,capacity) VALUES ('8829','นิสสัน','UG780' ,'รถยนต์บรรทุกปกติขนาดใหญ่','เขียว','6' ,'140','ND6-026175','UG780-24610' ,'2','24','44500' ,'900-20','900-20','ลมดัน' ,'2300','4470','-----' ,'4545','5165','นิสสัน' ,'1980','ญี่ปุ่น','ป.สยามกลการ จำกัด' ,'-------','274800','Diesel','200')]
|
 |
 |
 |
 |
Date :
2012-02-07 19:35:19 |
By :
preacher |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองเปลี่ยนเป็น $objQuery = mysql_query($strSQL) or die (mysql_error()) ;
|
 |
 |
 |
 |
Date :
2012-02-07 19:38:17 |
By :
ozma |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เปลี่ยนตรงไหนครับ
ตรงนี้เปล่าครับ $objQuery = mysql_query($strSQL);
|
 |
 |
 |
 |
Date :
2012-02-07 19:40:01 |
By :
preacher |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ออกมาเป็นแบบนี้ครับ เพราะไร แก้ยังไงครับ ช่วยที
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 'long,high,weight,Load,factory,year,product_country,purchased_fr
|
 |
 |
 |
 |
Date :
2012-02-07 19:52:55 |
By :
preacher |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอเอา code ด้านบนมาทำใหม่นะคับ Code (PHP)
<html>
<head>
<title>ARTILLERY CAR ADDSAVE</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","") or die("ไม่สามารถติดต่อฐานข้อมูลได้ครับ");
$objDB = mysql_select_db("car1");
$strSQL = "INSERT INTO datacar ";
$strSQL .="(idcar,car_name,model,type,color,piston,horsepower,engine_number,vehicle_numbers,battery,volt,wheel,front_wheel,rear_wheel,type_rubber,width,long,high,weight,Load,factory,year,product_country,purchased_from,contract_number,price,type_oil,capacity) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtidcar"]."','".$_POST["txtcar_name"]."','".$_POST["txtmodel"]."' ";
$strSQL .=",'".$_POST["txttype"]."','".$_POST["txtcolor"]."','".$_POST["txtpiston"]."' ";
$strSQL .=",'".$_POST["txthorsepower"]."','".$_POST["txtengine_number"]."','".$_POST["txtvehicle_numbers"]."' ";
$strSQL .=",'".$_POST["txtbattery"]."','".$_POST["txtvolt"]."','".$_POST["txtwheel"]."' ";
$strSQL .=",'".$_POST["txtfront_wheel"]."','".$_POST["txtrear_wheel"]."','".$_POST["txttype_rubber"]."' ";
$strSQL .=",'".$_POST["txtwidth"]."','".$_POST["txtlong"]."','".$_POST["txthigh"]."' ";
$strSQL .=",'".$_POST["txtweight"]."','".$_POST["txtLoad"]."','".$_POST["txtfactory"]."' ";
$strSQL .=",'".$_POST["txtyear"]."','".$_POST["txtproduct_country"]."','".$_POST["txtpurchased_from"]."' ";
$strSQL .=",'".$_POST["txtcontract_number"]."','".$_POST["txtprice"]."','".$_POST["txttype_oil"]."','".$_POST["txtcapacity"]."')";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "บันทึกเรียบร้อยแล้วครับ";
}
else
{
echo "ไม่สามารถบันทึกได้ครับ [".$strSQL."]";
}
mysql_close($objConnect);
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2012-02-07 20:09:41 |
By :
slurpee55555 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง copy อันนี้ไปดูครับ
Code (PHP)
$strSQL .="('".$_POST["txtidcar"]."','".$_POST["txtcar_name"]."','".$_POST["txtmodel"]."'";
$strSQL .=",'".$_POST["txttype"]."','".$_POST["txtcolor"]."','".$_POST["txtpiston"]."'";
$strSQL .=",'".$_POST["txthorsepower"]."','".$_POST["txtengine_number"]."','".$_POST["txtvehicle_numbers"]."'";
$strSQL .=",'".$_POST["txtbattery"]."','".$_POST["txtvolt"]."','".$_POST["txtwheel"]."'";
$strSQL .=",'".$_POST["txtfront_wheel"]."','".$_POST["txtrear_wheel"]."','".$_POST["txttype_rubber"]."'";
$strSQL .=",'".$_POST["txtwidth"]."','".$_POST["txtlong"]."','".$_POST["txthigh"]."'";
$strSQL .=",'".$_POST["txtweight"]."','".$_POST["txtLoad"]."','".$_POST["txtfactory"]."'";
$strSQL .=",'".$_POST["txtyear"]."','".$_POST["txtproduct_country"]."','".$_POST["txtpurchased_from"]."'";
$strSQL .=",'".$_POST["txtcontract_number"]."','".$_POST["txtprice"]."','".$_POST["txttype_oil"]."','".$_POST["txtcapacity"]."')";
ได้ไม่ได้บอกด้วยนะครับ  
|
 |
 |
 |
 |
Date :
2012-02-07 20:13:46 |
By :
slurpee55555 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เหมือนเดิมครับ รับข้อมูลเข้าไม่ได้
ไม่สามารถบันทึกได้ครับ [INSERT INTO datacar (idcar,car_name,model,type,color,piston,horsepower,engine_number,vehicle_numbers,battery,volt,wheel,front_wheel,rear_wheel,type_rubber,width,long,high,weight,Load,factory,year,product_country,purchased_from,contract_number,price,type_oil,capacity) VALUES ('8829','นิสสัน','UG7802','รถยนต์บรรทุกปกติขนาดใหญ่','เขียว','6','140','ND6-026175','UG780-24610','2','24','44500','900-20','900-20','ลมดัน','2300','4470','5555','4545','5165','นิสสัน','1980','ญี่ปุ่น','ป.สยามกลการ จำกัด','08999999','274800','Diesel','200')]
พอใส่โค๊ด $objQuery = mysql_query($strSQL) or die (mysql_error()) ;
ผล เป็นอย่างนี้ครับ
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 'long,high,weight,Load,factory,year,product_country,purchased_fr
|
 |
 |
 |
 |
Date :
2012-02-07 20:30:51 |
By :
preacher |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ติดคำสงวนหรือป่าวครับ
เปลี่ยน 3 ตัวนี้ครับ ตั้งชื่อใหม่ครับ ผมคิดว่าน่าจะเป็นคำสงวนครับ
( long load year )
|
 |
 |
 |
 |
Date :
2012-02-07 20:54:47 |
By :
slurpee55555 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|