user1021482
user1021482

Reputation: 13

php mysql insert error

<?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: 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 1

i have the echos only for debugging... i am still having an error and there is no explanation for that. Everything is correct...

i have 23 columns in the database.. All the names are correct.. and i still always having error on the insert in columns 'desk', 'oper'.

these columns in the structure are 'varchar(100)'

Thanks in advance.

Upvotes: 1

Views: 823

Answers (3)

group is a reserved word in SQL. (GROUP BY). You must quote it using the ``-quotes.

linex, `group`, oper

Upvotes: 2

Marco
Marco

Reputation: 57593

You shoul try to escape field names if they are reserver words:

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')

Upvotes: 0

Haim Evgi
Haim Evgi

Reputation: 125614

group is one of the reserved word in mysql use like `group`

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

Upvotes: 0

Related Questions