I'm having a problem regarding these 3 queries:
select count(*) as rec_count from test_history inner join
test_detail on test_history.history_id = test_detail.test_history_id
where test_history.history_id in ({$_SESSION['history_ids']})
and test_history.user_id = $userID
and
select count(*) as correct_answers from test_history inner join test_detail
on test_history.history_id = test_detail.test_history_id
where test_history.history_id in ({$_SESSION['history_ids']}) and
test_history.user_id = $userID and is_correct = 1
and this one
select * from test_topics inner join
test_topics_link on test_topics.`topic_id` = test_topics_link.`topic_id`
where test_topics_link.test_id in ({$_SESSION['ids_tests']}) and percentage > 0
I'm always getting 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 ') and
test_history.user_id = 82' at line 3
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 ') and
test_history.user_id = 82 and is_correct = 1' at line 2
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 ')' at line 1
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 ') and percentage > 0' at
line 3
Since $_SESSION['ids_tests'], I suppose, is an array, you should write implode(',',$_SESSION['ids_test']), e.g. in PHP it should be:
$query = "select * from test_topics inner join
test_topics_link on test_topics.`topic_id` = test_topics_link.`topic_id`
where test_topics_link.test_id in (".
implode(',',$_SESSION['ids_tests']).") and percentage > 0";
Related
I am trying to execute this mySQL query in PHP.
$sql = "SELECT * FROM Property
WHERE CONCAT(name, '',
contact_number , '',
hostel_address,'',
renter_name,'',
other_details,'',
date_posted,'') LIKE '%".$var."'
ORDER BY STR_TO_DATE(date_posted,'%d/%m/%Y')";
An I am getting following error:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'ORDER BY STR_TO_DATE(date_posted,'%d/%m/%Y') ASC' at line 1
Any help here :(
may try this:
$sql = "SELECT * FROM Property WHERE CONCAT(name, '',contact_number , '', hostel_address,'',renter_name,'',other_details,'',date_posted,'') LIKE '%".$var."' ORDER BY STR_TO_DATE(date_posted,'%d/%m/%Y')";
Note that there should be an ending single quote before ORDER BY
I got an Error while trying to convert my database.
Fehler in 163 - 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 ')' at line 2
Query war : SELECT * FROM phpbb_users WHERE user_active = 1 AND user_id NOT IN ()
My Code:
$e0 = query("SELECT * FROM ".$phpbb_prefix."_users
WHERE user_active = 1 AND user_id NOT IN (".implode("','", $ilch_to_phpbb).")" , $phpbb_con)
or die('Fehler in '. __LINE__ . ' - '.mysql_errno($phpbb_con) . ' : '. mysql_error($phpbb_con).'<br /> Query war : ' . $lastquery . '<hr />');
I can not recognize the error. Any Ideas?
Database: MySQL(i) 5.5.53-0+deb7u1
PHP: 5
The problem is with your implode. Imagine if $ilch_to_phpbb contains 2 user id's, the query will be:
SELECT * FROM ".$phpbb_prefix."_users
WHERE user_active = 1 AND user_id NOT IN (2','3)
That's obviously invalid SQL syntax.
You either need to drop the ' in the implode (although this will cause a SQL error if $ilch_to_phpbb is empty, because NOT IN () is invalid SQL), or add ' around it in the query:
AND user_id NOT IN ('".implode("','", $ilch_to_phpbb)."')
I have the Following SQL Query whic runs perfectly in codeigniter version 3
It Shows error in version 2.
$this->db->select('*');
if($cond!=''){
$this->db->where($cond);
}
$this->db->from('(select * from products1 where pr_id in('.implode(",",$condin).') order by pr_id asc) as a ');
$this->db->join(PRICE_TABLE.' as b','a.pr_id=b.pr_id','inner');
$this->db->limit($limit);
$query=$this->db->get();
return $query;
The error is
A Database Error Occurred
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 'order by pr_id asc) as a) INNER JOIN `pr_product_attr_usa_new` as b ON `a`.`pr_i' at line 2
SELECT * FROM ((select * from products1 where pr_id in(752, `6263`, `542`, `2059)` order by pr_id asc) as a) INNER JOIN `pr_product_attr_usa_new` as b ON `a`.`pr_id`=`b`.`pr_id` WHERE `b`.`pr_stock` = 'yes' LIMIT 6
Filename: D:\XAMPP\htdocs\pr_sites\us\chk\system\database\DB_driver.php
Line Number: 331
The issue is related to the code:
in('.implode(",",$condin).')
which output:
(752, `6263`, `542`, `2059)`
instead of:
(752, `6263`, `542`, `2059`)
The ` symbol is outside the ')'.
Hi I have a query in php file which is used to filter the data in file from mysql database
$_SESSION['sc_session'][$this->Ini->sc_page]['grid_deposit']['where_orig'] = " where Reg_no = \"69\"";
In this line if Reg_no = \"69\"" , if i change the 69 to any value data is being modified but if i use an array instead of 69 then its not working like this
$_SESSION['sc_session'][$this->Ini->sc_page]['grid_deposit']['where_orig'] = " where Reg_no = " . $fc . "";
But if i use
$fc = 69;
echo $fc;
Then its working but not on that line please tell me how to code this The error on which i get is
Error
Error while accessing the database:
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 '' at line 1
select count(*) from deposit where Reg_no =
from your Reg_no =\"69\""
and your Reg_no =". $fc."";
are you not missing the "" of the $fc
$_SESSION['sc_session'][$this->Ini->sc_page]['grid_deposit']['where_orig'] = " where Reg_no = \"" . $fc . "\"";
to match your 69 example.
In your original question you stated this error text
Error
Error while accessing the database:
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 '' at line 1
select count(*) from deposit where Reg_no =
If the $fc would be an array you would see this in the query as such. If i remember correctly it would look like that ...
Error
Error while accessing the database:
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 '' at line 1
select count(*) from deposit where Reg_no = Array
As it does not i assume that the variable $fc is empty. Did you check the variable or better create the query and log it somewhere to check the query as it gets sent to the sql server.
As mentioned, if it would be an array PHP would convert it when wrongly used to the text "Array" which you should find in the query.
i guess you try to do something like
"where Reg_no IN (".implode(",", $fc).")";
Help me!
SELECT ma_forum.*, ma_forum_cat.*
FROM ma_forum, ma_forum_cat
JOIN ma_forum_comentarios ON ma_forum_comentarios.not_id = ma_forum.not_id
GROUP BY ma_forum.not_id
WHERE ma_forum.notcat_id=ma_forum_cat.notcat_id AND ma_forum.notcat_id='".$notcat_id."'
AND ma_forum.not_status='Ativo'
ORDER BY MAX(ma_forum_comentarios.comnot_data) DESC
"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 ma_forum.notcat_id=ma_forum_cat.notcat_id AND ma_forum.notcat_id='1' ' at line 9"
Your query is in the wrong order; GROUP BY should be after WHERE and before ORDER BY:
SELECT ma_forum.*, ma_forum_cat.*
FROM ma_forum, ma_forum_cat
JOIN ma_forum_comentarios ON ma_forum_comentarios.not_id = ma_forum.not_id
WHERE ma_forum.notcat_id=ma_forum_cat.notcat_id AND ma_forum.notcat_id='".$notcat_id."'
AND ma_forum.not_status='Ativo'
GROUP BY ma_forum.not_id
ORDER BY MAX(ma_forum_comentarios.comnot_data) DESC
I don't know what database you're using, but here's a link to MySQL's SELECT syntax