PHP database related error, and MySQL error - php

This is the error I receive when I type in code further down:
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 'order(order_date,cust_firstname,cust_lastname,cust_add,cust_city,cust_state,indi' at line 1
The code for this error is:
<?php
include "db.php";
$cust_firstname=$_POST['name'];
$cust_lastname=$_POST['lastname'];
$cust_add=$_POST['add'];
$cust_city=$_POST['city'];
$cust_state=$_POST['state'];
$cust_country=$_POST['country'];
$cust_zip=$_POST['pincode'];
$cust_phone=$_POST['mobile'];
$cust_email=$_POST['email'];
$sql=mysql_query("INSERT INTO order(order_date,cust_firstname,cust_lastname,cust_add,cust_city,cust_state,$cust_country,cust_zip,cust_phone,cust_email)values(now(),'$cust_firstname','$cust_lastname','$cust_add','$cust_city','$cust_state','$cust_country','$cust_zip','$cust_phone','$cust_email')")or die(mysql_error());
header("location:done.php");
?>
What I'm wondering, is what this error really means and what I have to do to fix it?

Order is a reserved keyword. You need to wrap it in ticks:
$sql=mysql_query("INSERT INTO `order` (order_date,

try this
$sql=mysql_query("INSERT INTO `order` (order_date,cu.....
order is reserved key word in mysql
EDIT:
change this
$cust_country
to
cust_country
in insert statment columns

Related

You have an error in your SQL syntax with table and connection

Im getting this error, I can't figure out why thought:
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 'Case (clientforename, clientsurname) VALUES ('ghghgj', 'ffhhf')' at line 1
this is the php code:
mysql_query("INSERT INTO Case (clientforename, clientsurname)
VALUES ('$clientforename', '$clientsurname')")
or die(mysql_error());
Case is a reserved keyword. You must wrap it in ticks:
mysql_query("INSERT INTO `Case` (clientforename, clientsurname)
VALUES ('$clientforename', '$clientsurname')")
or die(mysql_error());

error in mysql insert query in MYSQL 5.6.12

I tried to use the following code to insert,
$op=$_POST["ans"];
$username=$_GET["username"];
mysql_query("insert into $username values('Q3','$op')")
or die(mysql_error());
But I got the following 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 'values('Q1','Wrong')' at line 1
Why am I getting this error? How can I fix it?
Your query structure is not making any sense. You're inserting into $username? That's not the name of the table, is it?
mysql_query("INSERT INTO `tablename` values('Q3','" . mysql_real_escape_string($op) . "')") or die(mysql_error());
Always be very careful to escape any and all user data being put into your queries, and please, please stop using mysql_query in new code.

Php mysqli->real_escape_string and MYSQL

I've a little question.
I've written this code to add the values to mysql database but when i run the code and I got an error. Can anybody help me?
the code:
$fel = $mysqli->query("INSERT INTO deleted (uid,buy_type,prop_type,district,street,room_min,room_max,price_min,price_max,condition_type,heat_type,lift_type,parking_type,type_of_del,when)
VALUES ('".$mysqli->real_escape_string($letomb['uid'])."',
'".$mysqli->real_escape_string($letomb['buy_type'])."',
'".$mysqli->real_escape_string($letomb['prop_type'])."',
'".$mysqli->real_escape_string($letomb['district'])."',
'".$mysqli->real_escape_string($letomb['street'])."',
'".$mysqli->real_escape_string($letomb['room_min'])."',
'".$mysqli->real_escape_string($letomb['room_max'])."',
'".$mysqli->real_escape_string($letomb['price_min'])."',
'".$mysqli->real_escape_string($letomb['price_max'])."',
'".$mysqli->real_escape_string($letomb['condition_type'])."',
'".$mysqli->real_escape_string($letomb['heat_type'])."',
'".$mysqli->real_escape_string($letomb['lift_type'])."',
'".$mysqli->real_escape_string($letomb['parking_type']).",
'".$mysqli->real_escape_string($type_of_del)."',
now())") or die($mysqli->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 'when) VALUES ('3', 'kiado', 'lakas', '1'' at line 1
WHEN is a reserved word. Enclosing it in backticks should fix your problem, as it will then be treated as an identifier.
`when`
You should use backticks around your column names. when is a MySQL keyword so it's being interpreted incorrectly. At the very least use backticks around when.

Annoying mysql update query problem

I'm trying to update using mysql_query in php and it gives me this 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 'read='1' WHERE id='14'' at line 1
I've been looking at my query for about 10 minutes now and I cant find whats wrong with it. Here it is:
if ($row['read'] == 0) {
mysql_query("UPDATE mail SET read='1' WHERE id='$mailid'") or die(mysql_error());
}
Do anyone see where the error is?
read is a reserved word.
Enclose it into the backticks:
UPDATE mail SET `read`='1' WHERE id='$mailid'
How about...
"UPDATE `mail` SET `read`='1' WHERE `id`='".$mailid."'"
read is a reserved word. You need to use backticks ` around read.

MySQL INSERT error

I got this error :
Database problem occur, please try again later.
- Error in query: INSERT INTO main SET title ='', url='www.jerseymurah.com', kod='jerseymurah', owner='Hasbul Aqill', tag='jersey, football, world cup', since='Feb 2010', desc='ssfsfsfsfs'
- 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 'desc='ssfsfsfsfs'' at line 1 (Error #1064)
- File: /home/yosh/domains/yosh.my/public_html/demo/admincp/tambah-save.php
and this is my mysql query code :
$query = "INSERT INTO main SET title ='".$ttile."', url='".$url."',
kod='".$kod."', owner='".$owner."', tag='".$tag."', since='".$since."',
desc='".$desc."'";
$db->rq($query);
Please help and thanks a lot!
DESC is a reserved word in mySQL.
You need to put that field in backticks:
`desc`="..."
maybe consider renaming the field.
mySQL reserved words in the manual
I think DESC is a reserved word, try escaping it with backticks.
mysql_query("INSERT INTO main(title,url,kod,owner,tag,since,description) VALUES('$title','$url','$kod','$owner','$tag','$since','$desc')");

Categories