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 rowid = 1' at line 1

Hi i have this custom module in dolibarr. Im new to it. How can i fix this code that the error says

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 rowid = 1’ at line 1

I think my code is okay

$sql = “UPDATE “.MAIN_DB_PREFIX.$this->table_element;
$sql .= “SET ref = '”.$this->db->escape($num).”’,”;
$sql .= “status = “.self::STATUS_VALIDATED.”,”;
$sql .= “date_valid =’”.$this->db->idate($now)."’,";
$sql .= "fk_user_valid` = ".$user->id;
$sql = "WHERE rowid = ".$this->id;

can someone help me figured this thing out?? why the error says in rowid…

Any help is muchly appreciated. TIA

Hello,

Activate the debug bar and see the complete SQL request syntaxe to understand what is the issue.
I think a space is missing before WHERE but this need to be investigated.

Hi @ksar ,

Yes i already activate the debug bar this is what i see

It says the line is WHERE

Debugg bar is a module that you need to activate.
Then you will have this :

Hi @ksar,

Yes i activated that. this is the error

it clearly says

  • WHERE rowid = 1 [DB_ERROR_SYNTAX] 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 rowid = 1’ at line 1

Yes I know, and you keep repeating the same thing since 3 posts.
And I repeat my :

okay will check . dont understand why it becomes error. hmmmm so far my code is okay

I also add a space in WHERE and it throws an error

hello i got the same error when trying to delete an excess paid saved as available discount, here is the debug
UPDATE llx_facture_fourn set paye=0, fk_statut=1 WHERE (type IN (2,3) AND rowid = 187 2.46[DB_ERROR_SYNTAX] 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 ‘’ at line 1

i have same problem