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: 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.

1
  • 1
    Please make some reading about SQL injections. What if $obs equals foo'); <DO SOMETHING BAD> -- Commented Oct 31, 2011 at 6:44

3 Answers 3

2

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

linex, `group`, oper
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.