2011-10-31 122 views
1
<?php 
$inv = $_POST['inv']; 
$box = $inv; 
$date = $_POST['from']; 
$mark = $_POST['mark']; 
$type = $_POST['type']; 
$desc = $_POST['desc']; 
$machine = $_POST['machine']; 
$serial = 'x'; 
$cmode = $_POST['cmode']; 
$t1 = $_POST['t1']; 
$t2 = $_POST['t2']; 
$t3 = $_POST['t3']; 
$t4 = $_POST['t4']; 
$t5 = $_POST['t5']; 
$t6 = $_POST['t6']; 
$org = $_POST['org']; 
$plant = $_POST['plant']; 
$floor = $_POST['floor']; 
$line = $_POST['line']; 
$linex = $_POST['linex']; 
$group = $_POST['group']; 
$oper = $_POST['oper']; 
$obs = $_POST['obs']; 

echo $box.'<br/>'; 
echo $date.'<br/>'; 
echo $inv.'<br/>'; 
echo $mark.'<br/>'; 
echo $type.'<br/>'; 
echo $desc.'<br/>'; 
echo $machine.'<br/>'; 
echo $serial.'<br/>'; 
echo $cmode.'<br/>'; 
echo $t1.'<br/>'; 
echo $t2.'<br/>'; 
echo $t3.'<br/>'; 
echo $t4.'<br/>'; 
echo $t5.'<br/>'; 
echo $t6.'<br/>'; 
echo $org.'<br/>'; 
echo $plant.'<br/>'; 
echo $floor.'<br/>'; 
echo $line.'<br/>'; 
echo $linex.'<br/>'; 
echo $group.'<br/>'; 
echo $oper.'<br/>'; 
echo $obs.'<br/>'; 

$con = mysql_connect("localhost","username","mypassword"); 
if (!$con) { die('Could not connect: ' . mysql_error()); } 
mysql_select_db("brisay", $con); 
mysql_query("SET NAMES utf8"); 

$sql="INSERT INTO controller (box, date, inv, mark, type, machine, serial, cmode, t1, t2, t3, t4, t5, t6, org, plant, floor, line, linex, group, oper, obs) VALUES('$box','$date','$inv','$mark','$type','$machine','$serial','$cmode','$t1','$t2','$t3','$t4','$t5','$t6','$org','$plant','$floor','$line','$linex','$group','$oper','$obs')"; 
if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } 

错误: 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 'group, oper, obs) VALUES ('123456','2011-10-07','123456','mark','type','4455','x' at line 1PHP的MySQL插入错误

我有回声仅用于调试... 我仍然有一个错误,也没有解释这一点。一切都是正确的...

我在数据库中有23列.. 所有的名称都是正确的..我仍然总是有错误插入列'桌子','操作员'。

在结构中的这些列是 'VARCHAR(100)'

预先感谢。

+1

请阅读有关SQL注入的内容。如果'$ obs'等于'foo'); --' – 2011-10-31 06:44:14

回答

0

你建议立即进行删除尝试,如果他们是储库的话逃脱的字段名称:

INSERT INTO controller 
(box, `date`, inv, mark, `type`, machine, serial, cmode, 
t1, t2, t3, t4, t5, t6, org, plant, `floor`, line, linex, 
`group`, oper, obs) 
VALUES 
('$box','$date','$inv','$mark','$type','$machine','$serial','$cmode', 
'$t1','$t2','$t3','$t4','$t5','$t6','$org','$plant','$floor','$line', 
'$linex','$group','$oper','$obs') 
+0

我逃脱了每一个字,它像一个魅力工作,谢谢。 – user1021482

2

组是SQL中的保留字。 (通过...分组)。你必须用`` - 引号引用它。

linex, `group`, oper 
0

是在MySQL中reserved word之一 使用像`group`

INSERT INTO controller (....,`group`, ........