I am attempting to create a plugin for CakePHP 1.3, but I am having the following error that is frustrating me:
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 'process' at line 1
I have tried multiple things but have not come up with a solution;
Basically I call the following from my app_controller.php file:
var $uses = array('Visitor.Visitors');
function beforeRender(){
$this->Visitors->process($this->here);
}
And then I have the following in my visitor.php model file in my plugin
class Visitor extends VisitorsAppModel {
var $name = 'Visitor';
function process($url = null){
$this->deleteInactive();
if($this->_isBot() == FALSE){
$this->_updateVisitor($url);
}
}
}
The strange thing is that even if I comment out the above function I still get the same MySQL error 1064.
Help!
Try changing 'Visitors' in $this->Visitors->process($this->here); to 'Visitor' (singular).
It seems also that you have swapped 'Visitors' and 'Visitor' in the $uses array of your app_controller.php file:
var $uses = array('Visitor.Visitors');
should be
var $uses = array('Visitors.Visitor');
Related
I have a (currently localhost, but soon to be through AWS) Node.JS server with Express and I'm trying to update an RDS instance through a MySQL query when I'm getting the following error:
{ [Error: ER_PARSE_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 ''history0' = 'http://localhost:3000/' WHERE id = 1' at line 1]
code: 'ER_PARSE_ERROR',
errno: 1064,
sqlMessage: '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 \'\'history0\' = \'http://localhost:3000/\' WHERE id = 1\' at line 1',
sqlState: '42000',
index: 0,
sql: 'UPDATE infected SET \'history0\' = \'http://localhost:3000/\' WHERE id = 1;' }
The POST request causing the error:
app.post('/history', function(req, res) {
var hist = 'history' + 0;
var sql = 'UPDATE infected SET ? = ? WHERE id = ?;';
connection.query(sql, [hist, req.body[0].url, 1]);
});
I'm using hist as a variable because I plan to have it in a loop, but I wasn't sure if the way I'm declaring it here is causing the issue so I left it as is. req.body is the output of JSON.stringify() called on call to chrome.history.search(). So I'm trying to get the URL of the entry at index 0.
I've tried a direct call to connection.query with a hard-coded string as follows:
connection.query("UPDATE infected SET history0='google.com' WHERE id='1'");
and it successfully updates the database, so I figure there's an issue with how I'm using the question marks to insert variables hist and req.body[0].url into the query, but I can't figure out what the issue is.
try with double "??" for the keys, this way:
app.post('/history', function(req, res) {
var hist = 'history' + 0;
var sql = 'UPDATE infected SET ?? = ? WHERE id = ?;';
connection.query(sql, [hist, req.body[0].url, 1]);
});
I tried to use template queries to construct my sql query. Here's the sample code:
unsigned int version = 2;
try {
// key_version is INT UNSIGNED
mysqlpp::Query query = conn->query("SELECT * FROM agentlist WHERE key_version != %0q");
mysqlpp::StoreQueryResult res = query.store(version);
// string type param also caused the same problem
// mysqlpp::StoreQueryResult res = query.store(std::to_string(version));
} catch (const exception &ex) {
// deal with exceptions
}
And the code would go to catch part. ex.what():
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 \'2\' at line 1
I think it was caused by SQLQueryParms type, but the neither the tutorial nor the documentation had shown any methods to work around this.
BTW, how do I get parsed query string (with template params substituted)? I tried query.str(version) but it was same as query.str().
My bad. Forgot an important function call query.parse().
And it all works now.
I am trying to perform a post call in node js, i am testing it through post but i am not able to retrive data,
my node code,
exports.login = function( req, res ) {
console.log("Params:"+req.body.email);
//console.log('email:'+params.email);
connection.query('SELECT * FROM profile where email ='+req.body.email,function(error,result,rows,fields){
if(!!error){console.log(error)
console.log('fail');
}else{
console.log(result);
res.send(result);
}
// }
});}
my routes,
router.post('/login',cors(), admin.login);
i am getting fail and my error is
{ [Error: ER_PARSE_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 '#gmail.com' at line 1]
my input through postman
{"email":"s#gmail.com"}
Don't build the query string directly, this leaves you open to injection attacks and also chokes on certain characters, as you are experiencing here. Use a placeholder like so:
var query = "select * from profile where email = ?";
connection.query(query, [req.body.email], function(error,result,rows,fields) {
...
I do request to MySQL database, which searches data in table by criteria:
def tableAcounting(){
def user = Person.findByUsername(springSecurityService.currentUser.username)
def cafee = user.cafee
def tablesQuery = TablePlacesInfo.createCriteria()
def tables = tablesQuery.list { //AN ERROR SHOW ON THIS STRING
'in'("hall", HallsZones.findAllByCafee(cafee))
}
def halls = cafee.halls
But I get such error:
Class:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException
Message: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
This usually happends if you do an in search using an empty set. This means, that you need to check the size of HallsZones.findAllByCafee(cafee) because this set is probably empty.
$this->db->select('*');
$this->db->from('product');
$this->db->where('del_in !=',1);
$query=$this->db->get();
return $query;
I am getting sql following error Please help me to solve 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 '' at line 3
SELECT * FROM (`product`) WHERE `del_in` != 1 LIMIT 0 ,
Filename: D:\wamp\www\shopcart\system\database\DB_driver.php
Just make sure column name and table name are correct. After that try this code
$this->db->select('*');
$this->db->where('del_in !=',1);
$this->db->from('product');
$query=$this->db->get();
return $query->result();