You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syn

Please report bugs and any annoyances here. Kindly include all possible details: steps to reproduce, expected result, actual result, screenshots, ... etc.
Post Reply
lawrencekeru
Posts: 29
Joined: 2016-06-24 02:51

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syn

Post by lawrencekeru » 2016-10-19 09:55

Hi

Everytime i access my application for the first time, i get the above error.

But when i press the Signin, The error disappears and am redirected to the login page.

I cant seem to find the query that is throwing the error.
error.JPG
error.JPG (69.54 KiB) Viewed 57712 times
Please assist..

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right

Post by DevGiu » 2016-10-19 11:33

DId you checked your _global, header_extras and footer_extras files?
/Giuseppe
Professional Outsourcing Services

lawrencekeru
Posts: 29
Joined: 2016-06-24 02:51

Re: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right

Post by lawrencekeru » 2016-10-20 13:50

Hi DevGiu,

I relooked into the 3 files but cannot see any problem with my queries. header_extras is blank, footer_extra has no sql query the only query is in _global.php

Look at how it looks like, please help me identify a problem if there is one.

Code: Select all

<?php
	// For help on using hooks, please refer to http://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks

	function login_ok($memberInfo, &$args){
		$username = $memberInfo['username'];
		$ip = $memberInfo['IP'];
		$date = date("Y-m-d H:i:s A");
		$details = "LOGIN";
		$session_id = session_id();

		sql("insert into audit_trail set username = '{$username}', ip = '{$ip}', ts = '{$date}', details = '{$details}'", $eo);
		return ' ';
	}

	/*function logout_ok($memberInfo, &$args){
		//$logout = $memberInfo['username'];
		$ip = $memberInfo['IP'];
		$logout_date = date("Y-m-d H:i:s A");
		$details = "LOGOUT";
		$session_id_now = session_id();

		sql("update audit_trail set logout_ts = '{$logout_date}', logout_details = '{$details}' WHERE session_ID = '{$session_id_now}'", $eo);
		return ' ';
	}
      */
	function login_failed($attempt, &$args){
		$username = $attempt['username'];
		$ip = $_SERVER['REMOTE_ADDR'];
		$ts = date("Y-m-d H:i:s A");
		$details = makeSafe("LOGIN FAILED. Username : {$attempt['username']}");
		sql("insert into audit_trail set username = '{$username}', ip = '{$ip}', ts = '{$ts}', details = '{$details}'", $eo);
	}

	function member_activity($memberInfo, $activity, &$args){
		switch($activity){
			case 'pending':
				break;

			case 'automatic':
				break;

			case 'profile':
				break;

			case 'password':
				break;

		}
	}

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right

Post by DevGiu » 2016-10-20 14:06

Insert statement is wrong.

Should be something like

Code: Select all

insert into audit_trail (username, ip, date, details) VALUES ('{$username}',  '{$ip}', '{$date}', '{$details})'
/Giuseppe
Professional Outsourcing Services


DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right

Post by DevGiu » 2016-10-20 15:43

If you comment the line error disappears? Can you post your corrected sql line¿?
/Giuseppe
Professional Outsourcing Services

lawrencekeru
Posts: 29
Joined: 2016-06-24 02:51

Re: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right

Post by lawrencekeru » 2016-10-20 15:54

Hey,

I figured it out.

Its was in links-home.php.

And the line throwing that error was

Code: Select all

$tenants_count = sqlValue("select count(*) from ".get_sql_from('applicants_and_tenants')); 

DevGiu
AppGini Super Hero
AppGini Super Hero
Posts: 151
Joined: 2016-05-27 09:08

Re: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right

Post by DevGiu » 2016-10-20 16:11

Then probably the error is because SQL is not builded corretly, maybe because get_sql_from('applicants_and_tenants') is returning false or something like this. Are you sure applicants_and_tenants is a table in your system and you have access to it?

Wrap your sql this way

Code: Select all

$applicants_and_tenants_where = get_sql_from('applicants_and_tenants');
if(!$applicants_and_tenants_where){ 
   // Here get_sql_from is returning false (without access, and table don't exists) and for this reason SQL is not builded correctly and giving an error.
   $tenants_count = 0; 
 } else {
   $tenants_count = sqlValue("select count(*) from {$applicants_and_tenants_where}"); 
}
/Giuseppe
Professional Outsourcing Services


Post Reply