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).")";
Related
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)."')
Hello stackoverflow community, I need help with this mysqli query. My auto increase column in database is ZERO-FILL element for example 00001 so when I try to query like this:
$stmt = $mysqli->query("UPDATE ".$db_table_prefix."korteles
SET
vardas = '".$this->clean_k_name."',
pavard = ".$this->clean_k_surname.",
WHERE korteles_nr = '00001'");
And I get 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 'WHERE korteles_nr = 00001' at line 18
I was searching Internet for solving this problem. But can't find so please help!
Query should be like this:-
$stmt = $mysqli->query("UPDATE ".$db_table_prefix."korteles
SET
vardas = '$this->clean_k_name',
pavard = '$this->clean_k_surname'
WHERE
korteles_nr = '00001'");
You have to remove the comma after $this->clean_k_surname variable
I am using this database class for my project: GitHub.
When trying to execute a SHOW query to determine whether a table exists or not I receive this error:
Fatal error: Problem preparing query (SHOW TABLES LIKE users) 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 'users' at line 1 in mysqli.php on line 679
The query looks like this:
$result = $DATABASE->rawQuery("SHOW TABLES LIKE " . $TABLE);
$TABLE is obviously filled with a string, I double checked that.
Any idea what could be wrong?
You probably missed the quotes:
$result = $DATABASE->rawQuery("SHOW TABLES LIKE '" . $TABLE . "'");
The like statement it's value is wrong.
You should use:
BAD
$result = $DATABASE->rawQuery("SHOW TABLES LIKE 'value here' ");
Good
$result = $DATABASE->rawQuery("SHOW TABLES LIKE ? ");
$DATABASE->addParam($table);
I think you allso want to add % in front and after your $table :)
What exactly is the correct syntax for adding PHP variables to a MySQL string?
This is my query:
"SELECT cd.SectionID, cd.CompanyName, cd.ShowOnSite, cd.LiveDate, cd.EndDate, cds.SiteID, s.SiteName
FROM CompanyDirectory cd
LEFT JOIN CompanyDirectorySections cds ON cd.SectionID = cds.SectionID
LEFT JOIN Sites s ON cds.SiteID = s.SiteID
WHERE s.SiteID = " . $id . " AND cd.ShowOnSite = 'y'
ORDER BY cd.EndDate DESC"
But it throws the following:
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 cd.ShowOnSite = 'y' ORDER BY cd.EndDate DESC' at line 5
I have also tried WHERE s.SiteID = $id and WHERE s.SiteID = '" . $id . "' but to no avail. The former gives a blank screen, and the latter gives the aforementioned error. The variable is an integer.
I have tried the query in phpMyAdmin and it works perfectly, substituting the variable for an actual ID.
Note: if it's important, $id has been received from a form via $id = $_POST['id']; before the query, and then stripped and escaped.
Thanks.
If MySQL is saying there is an error near "AND cd.ShowOnSite = 'y'", this normally means there's an issue with whatever comes before it - in this case, the $id.
Can you print out the query in your PHP file? This may show you that $id is in fact blank, which would make the query look like "WHERE s.SiteID = AND cd.ShowOnSite = 'y'".
If it's blank, there's obviously something wrong with the $id value which you will need to sort out before your MySQL code.
I have this query, running from a PHP page:
$feed_sql = "SELECT id, title, description, rssDate
FROM feed
WHERE MATCH (title) AGAINST ('" . $rows['suburb'] . "')
AND NOT EXISTS(SELECT feed_id, recipient_id, issent
FROM tracking_table
WHERE tracking_table.feed_id = $feed_id
AND tracking_table.recipient_id = $recipient_id
AND tracking_table.issent = 'Y')
GROUP BY pubDate
ORDER BY pubDate DESC
LIMIT 1";
However, it returns the following errors upon running it:
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 tracking_table.recipient_id =
AND tracki' at line 7
Line 7 being this:
AND tracking_table.recipient_id = $recipient_id
Some server information:
PHP Version 5.2.6-1+lenny9
MySQL Version 5.0.51a
Thanks :-)
As you can see here:
'AND tracking_table.recipient_id = AND tracki'
// value missing here --^
the value of $recipient_id seems to be empty and generates invalid syntax.
Perhaps $recipient_id is an empty string. Please check it