Forum Moderators: coopster
Couldn't execute query"insert into `mylists` (`name`,`owner`,`comments`,`completed`) values ('Me ','Me','testing''0', limit 1" 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 'limit 1' at line 1
My versions are:
PHP version 4.4.7
MySQL version 4.1.22-standard
I added a record manually in phpMyAdmin, and my update and delete scripts work, just not the insert....If you can find the error...I'll give you a cookie! ; )
else{
$query = "insert into `mylists` (`name`,`owner`,`comments`,`completed`) values ";
$query .= "('".db_escape($_POST['name'])."','".db_escape($_POST['owner'])."','".db_escape($_POST['comments'])."'";
if($_POST['completed'] == 'yes'){
$query .= "'1', ";
}else{
$query .= "'0', ";
}
$query .= " limit 1";
if(mysql_query($query)){
$output = '<b>Item added successfully!</b><br/><br/>';
}else{
$output = mysql_query($query) or die("Couldn't execute query\"$query\" error:" . mysql_error());
}
}
I do not use that style (it's me)
instead I opt for:
$name=db_escape($_POST['name']);
$owner=db_escape($_POST['owner']);
$comments=db_escape($_POST['comments']);
$completed=db_escape($_POST['completed'']);However you should before escaping verify that the expected POST values are the one expected...
$sql="insert into mylists (name, owner, comments, completed)
values
('$name', '$owner', '$comments', '$completed')";
Agreed, I usually opt for the above style as well, but I am adapting this script from another for my own needs....and so I am loathe to restructure the rest of the script : (
LifeinAsia - yeah I had messed with the code and got the comma in the right place, but missed the no closing parenthesis in that section....
I believe I have the comma correct now, but now I am unsure of where to put the closing parenthesis...below I added it to $query .= " limit 1"); and this is the error I get now:
Parse error: syntax error, unexpected ')' in ../list.php on line 214
else{
$query = "insert into `mylists` (`name`,`owner`,`comments`,`completed`) values ";
$query .= "('".db_escape($_POST['name'])."','".db_escape($_POST['owner'])."','".db_escape($_POST['comments'])."', ";
if($_POST['completed'] == 'yes'){
$query .= "'1' ";
}else{
$query .= "'0' ";
}
$query .= " limit 1");
if(mysql_query($query)){
$output = '<b>Item added successfully!</b><br/><br/>';
}else{
$output = mysql_query($query) or die("Couldn't execute query\"$query\" error:" . mysql_error());
}
}