What is wrong with my MySQL Query that is displaying the 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 'index WHERE id=1' at line 1
Relevant code:
$qu = mysql_query("SELECT * FROM index WHERE id= 1") or die("MySQL ERROR: ".mysql_error());
WHILE($d = mysql_fetch_array($qu)):
$con = $d['content'];
endwhile;
index is a MySQL reserved keyword, so you must quote it with backticks like this:
SELECT *
FROM `index`
WHERE id = 1
Related
when select images from a database below error is shown & after i delete record in the database its remain the same number inside (id)
this is the error
Error Number: 1064
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 '16,19,1,2,1,2,1 )' at line 1
select * from images where id in(,16,19,1,2,1,2,1 )
Filename: controllers/Admin.php
Line Number: 1046
and this is select statment :
if (!empty($data->images)) {
$qry = $this->db->query("select * from images where id in($data-
>images )");
$res['results'] = $qry->result();
}
and now my database is empty and this error still remaining ?
just remove the leading comma. like this.
select * from images where id in( 16,19,1,2,1,2,1 )
there is a leading comma in $data->images
$request_id_col and $request_id are strings. However, the request_id_col type in the table is an integer.
$stmt = $db->prepare(' SELECT r.qty, d.name
FROM requested_devices r
JOIN devices d ON r.device_id = d.id
WHERE r.:request_id_col = :request_id
ORDER BY r.id');
$stmt->bindParam(':request_id_col', $request_id_col);
$stmt->bindParam(':request_id', $request_id);
$stmt->execute();
I'm receiving 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 ''sample_id' = '101' ORDER BY r.id' at line 4'
How do I make a query by correctly using bindParam's?
You can't bind table or column names. Only values.
I have this query in Perl:
my $pkg="%";
my $sql = "SELECT pid, CAST(pid as UNSIGNED) AS l FROM xmld ORDER BY l WHERE pkg LIKE ?";
my $files_ref = $dbh->selectcol_arrayref($sql, undef, $pkg);
It crashes with:
DBD::mysql::db selectcol_arrayref failed: 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 'WHERE pkg LIKE '%'' at line 1 at ...
I have been looking at this statement for hours, tried various things, but no luck.
Where is that extra single quote coming from and how do I get rid of it?
order by goes after the where:
SELECT pid, CAST(pid as UNSIGNED) AS l
FROM xmld
WHERE pkg LIKE ?
ORDER BY l;
#1064 - 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 '-sporocilo us, uporabnik u WHERE ( 's%' LIKE
u.uuser) AND (s.SID = us.SID) AND (' at line 2
this is the error i get ...
SQL:
SELECT us.ussender, s.ssubject, s.scontent, us.ustimesend, us.usstatus,
FROM sporocilo s, uporabnik-sporocilo us , uporabnik u
WHERE ($user LIKE u.uuser) AND (s.SID = us.SID) AND (us.usreciever LIKE u.uuser),
ORDER BY us.ustimesend ASC;
Database: http://my.jetscreenshot.com/20224/20140415-ls6n-41kb
If your column identifiers are going to contain dashes you must wrap them in ticks. Otherwise MySQL assumes you are performing a subtraction operation.
SELECT us.ussender, s.ssubject, s.scontent, us.ustimesend, us.usstatus,
FROM sporocilo s, `uporabnik-sporocilo` us , uporabnik u
WHERE ($user LIKE u.uuser) AND (s.SID = us.SID) AND (us.usreciever LIKE u.uuser),
ORDER BY us.ustimesend ASC;
The syntax error is missing quotes, here:
WHERE ($user LIKE u.uuser) AND (s.SID = us.SID) AND (us.usreciever LIKE u.uuser),
plus the comma at the end of that line.
There are other problems with your query, but that is beyond the scope of your question.
I'm trying to delete some data from 3 tables. Here is my SQL:
DELETE
FROM productdetail
JOIN (productdescription,productmineralcategories,productspeciescategories)
ON
(
productdetail.id = productspeciescategories.id_product
AND productdetail.id = productmineralcategories.id_product
AND productdetail.id = productdescription.id_product
)
WHERE productdetail.id='".$data['id'].
And here is the output error:
Error Number: 1064
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 'JOIN (productdescription, productmineralcategories,
productspeciescategories) ' at line 3
What does it mean and how can I fix it?
Your DELETE statement should be:
$query="DELETE
FROM productdetail
WHERE productdetail.id='".$data[$id] . "'";
OR
$query="DELETE
FROM productdetail
WHERE productdetail.id='$data[$id]'";
OR do not add single quote if field type is numeric.
$query="DELETE
FROM productdetail
WHERE productdetail.id=$data[$id]";
Have a look at DELETE JOIN syntax.