I'm trying to create a IT asset database with a web front end.
我正在尝试使用Web前端创建IT资产数据库。
I've gathered some data from forms using POST as well as one variable that had already written to a cookie.
我已经使用POST从表单中收集了一些数据,以及一个已经写入cookie的变量。
This is the first time I have tried to enter the data into the database.
这是我第一次尝试将数据输入数据库。
Here is the code:
这是代码:
<?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");
?>
The error I get is: 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 '', '678 ', 'Server', '789')' at line 2
我得到的错误是:你的SQL语法有错误;查看与MySQL服务器版本对应的手册,以便在第2行'','678','Server','789')附近使用正确的语法
That data is just test data I was trying to throw in there, but it looks to be the at the $value, $type, $notes.
那些数据只是我试图抛出的测试数据,但它看起来是$ value,$ type,$ notes。
Here are the table create statements if they help:
以下是表创建语句,如果它们有帮助:
<?php
// 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());
// 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.</br />";
// create software table
mysql_query("CREATE TABLE software(
id VARCHAR(50) PRIMARY KEY,
software VARCHAR(50),
license VARCHAR(50))")
or die(mysql_error());
echo "Software Table Created.</br />";
// create laptop table
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.</br />";
// create desktop table
mysql_query("CREATE TABLE desktop(
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 "Desktop Table Created.</br />";
// create server table
mysql_query("CREATE TABLE server(
id VARCHAR(50) PRIMARY KEY,
manufacturer VARCHAR(50),
model VARCHAR(50),
warranty VARCHAR(50))")
or die(mysql_error());
echo "Server Table Created.</br />";
?>
Running a standard LAMP stack on Ubuntu 10.04.
在Ubuntu 10.04上运行标准LAMP堆栈。
Thank you.
谢谢。
4 个解决方案
#1
2
you are missing a opening quote, below is the corrected section:
你错过了一个开头的报价,下面是更正的部分:
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";
#2
3
you need a beginning quote ' before $purchase_order
在$ purchase_order之前你需要一个开头的报价
#3
3
You're missing a '
before $purchase_order.
你错过了'$ purchase_order之前的'。
#4
3
What Galen said. Plus your code is vulnerable to SQL Injection - and it will generally have problems with any user-input data with embedded single-quotes.
盖伦说的话。此外,您的代码容易受到SQL注入攻击 - 并且通常会出现嵌入单引号的任何用户输入数据的问题。
#1
2
you are missing a opening quote, below is the corrected section:
你错过了一个开头的报价,下面是更正的部分:
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";
#2
3
you need a beginning quote ' before $purchase_order
在$ purchase_order之前你需要一个开头的报价
#3
3
You're missing a '
before $purchase_order.
你错过了'$ purchase_order之前的'。
#4
3
What Galen said. Plus your code is vulnerable to SQL Injection - and it will generally have problems with any user-input data with embedded single-quotes.
盖伦说的话。此外,您的代码容易受到SQL注入攻击 - 并且通常会出现嵌入单引号的任何用户输入数据的问题。