我正在尝试使用Web前端创建IT资产数据库.
我已经使用POST从表单中收集了一些数据,以及一个已经写入cookie的变量.
这是我第一次尝试将数据输入数据库.
这是代码:
PHP
//get data
$id = $_POST['id'];
$company = $_POST['company'];
$location = $_POST['location'];
$purchase_date = $_POST['purchase_date'];
$purchase_order = $_POST['purchase_order'];
$value = $_POST['value'];
$type = $_COOKIE["type"];
$notes = $_POST['notes'];
$manufacturer = $_POST['manufacturer'];
$model = $_POST['model'];
$warranty = $_POST['warranty'];
//set cookies
setcookie('id',$id);
setcookie('company',$company);
setcookie('location',$location);
setcookie('purchase_date',$purchase_date);
setcookie('purchase_order',$purchase_order);
setcookie('value',$value);
setcookie('type',$type);
setcookie('notes',$notes);
setcookie('manufacturer',$manufacturer);
setcookie('model',$model);
setcookie('warranty',$warranty);
//checkdata
//start database interactions
// connect to MysqL server and database "asset_db"
MysqL_connect("localhost","asset_db","asset_db") or die(MysqL_error());
MysqL_select_db("asset_db") or die(MysqL_error());
// Insert a row of information into the table "asset"
MysqL_query("INSERT INTO asset
(id,company,location,purchase_date,purchase_order,value,type,notes) VALUES('$id','$company','$location','$purchase_date',$purchase_order','$value','$type','$notes') ")
or die(MysqL_error());
echo "Asset Added";
// Insert a row of information into the table "server"
MysqL_query("INSERT INTO server
(id,manufacturer,model,warranty) VALUES('$id','$manufacturer','$model','$warranty') ")
or die(MysqL_error());
echo "Server Added";
//destination url
//header("Location: verify_submit_server.PHP");
?>
我得到的错误是:
您的sql语法有错误;检查与MysqL服务器版本对应的手册,以便在第2行”,’678′,’Server’,’789′)附近使用正确的语法
那个数据只是我试图抛出的测试数据,但它看起来是$value,$type,$notes.
以下是表创建语句,如果它们有用:
PHP
// connect to MysqL server and database "asset_db"
MysqL_connect("localhost","asset_db") or die(MysqL_error());
MysqL_select_db("asset_db") or die(MysqL_error());
// create asset table
MysqL_query("CREATE TABLE asset(
id VARCHAR(50) PRIMARY KEY,company VARCHAR(50),location VARCHAR(50),purchase_date VARCHAR(50),purchase_order VARCHAR(50),value VARCHAR(50),type VARCHAR(50),notes VARCHAR(200))")
or die(MysqL_error());
echo "Asset Table Created.MysqL_query("CREATE TABLE software(
id VARCHAR(50) PRIMARY KEY,software VARCHAR(50),license VARCHAR(50))")
or die(MysqL_error());
echo "Software Table Created.MysqL_query("CREATE TABLE laptop(
id VARCHAR(50) PRIMARY KEY,manufacturer VARCHAR(50),model VARCHAR(50),serial_number VARCHAR(50),esc VARCHAR(50),user VARCHAR(50),prev_user VARCHAR(50),warranty VARCHAR(50))")
or die(MysqL_error());
echo "Laptop Table Created.MysqL_query("CREATE TABLE desktop(
id VARCHAR(50) PRIMARY KEY,warranty VARCHAR(50))")
or die(MysqL_error());
echo "Desktop Table Created.MysqL_query("CREATE TABLE server(
id VARCHAR(50) PRIMARY KEY,warranty VARCHAR(50))")
or die(MysqL_error());
echo "Server Table Created.
在Ubuntu 10.04上运行标准LAMP堆栈.
谢谢.
最佳答案