 |
Insert ข้อมูลเข้าไม่ได้เลย..... Insert ข้อมูลเข้าไม่ได้เลย Insert ข้อมูลเข้าไม่ได้เลย |
|
 |
|
|
 |
 |
|
ผมเพิ่งหัด php ส่งข้อมูลเข้า db ไม่ได้เลย
ปกติเขียน asp มา php ก็ติดแต่เริ่มเลย
Code
<?php
$con = mysql_connect("localhost","xxx","xxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxx", $con);
$sql="INSERT INTO book (book-name, book-des, book-value)
VALUES
('$_POST[bname]','$_POST[bdetail]','$_POST[value]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
มันฟ้องว่า
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 '-book (book-name, book-des, book-value) VALUES ('0000','0000','0000')' at line 1
Tag : PHP, MySQL
|
|
 |
 |
 |
 |
Date :
2011-04-10 12:49:59 |
By :
Akatsuki |
View :
780 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองแบบนี้ดูนะคัฟ..
$sql="INSERT INTO book ('book-name', 'book-des', 'book-value')
VALUES
('$_POST[bname]','$_POST[bdetail]','$_POST[value]')";
|
 |
 |
 |
 |
Date :
2011-04-10 13:56:34 |
By :
leksoft |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Syntax ผิดครับ ชื่อฟวด์ควรเป็น _ แทน - ครับ
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strSQL = "INSERT INTO customer ";
$strSQL .="(CustomerID,Name,Email,CountryCode,Budget,Used) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtCustomerID"]."','".$_POST["txtName"]."','".$_POST["txtEmail"]."' ";
$strSQL .=",'".$_POST["txtCountryCode"]."','".$_POST["txtBudget"]."','".$_POST["txtUsed"]."') ";
$objQuery = mysql_query($strSQL);
if($objQuery)
{
echo "Save Done.";
}
else
{
echo "Error Save [".$strSQL."]";
}
mysql_close($objConnect);
?>
</body>
</html>
Go to : PHP MySQL Add/Insert Record
|
 |
 |
 |
 |
Date :
2011-04-11 09:37:42 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|