PDO Error when using mysql_add_fun

Discuss MySQL Ajax Table Editor

PDO Error when using mysql_add_fun

Postby Dietmar » Mon Mar 26, 2018 1:18 pm

When I configure a column like this:

$tableColumns['mwst'] = array(
'display_text' => 'MwSt',
'perms' => 'VCXQT',
'mysql_add_fun' => "(anzahl * netto * mwstsatz / 100)",
'mysql_edit_fun' => "(anzahl * netto * mwstsatz / 100)"
);

I get the following error message:

insert into re_rechnungsdetails set `anzahl` = :anzahl, `rechnungstext` = :rechnungstext, `netto` = :netto, `mwstsatz` = :mwstsatz, `mwst` = (anzahl * netto * mwstsatz / 100)<br /><br />PDO parameter: anzahl => '1', rechnungstext => 'sdfasdfasdfasdf', netto => '20', mwstsatz => '19.0', mwst => ''
PDO Fehler:<br /> "SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens" on line: 343' in /srv/www/ensolutions.de/htdocs/r/mate/Common.php:26\nStack trace:\n#0 [internal function]: Common->logError('<br /><br />Fe...', '/srv/www/ensolu...', 1555, 'mate1_')\n#1 /srv/www/ensolutions.de/htdocs/r/mate/php/AjaxTableEditor.php(363): call_user_func(Array, '<br /><br />Fe...', '/srv/www/ensolu...', 1555, 'mate1_')\n#2 /srv/www/ensolutions.de/htdocs/r/mate/php/AjaxTa in /srv/www/ensolutions.de/htdocs/r/mate/Common.php on line 26, referer: http://ensolutions.de/r/mate/UploadToDb.php

when leaving the mysql_..._fun parameters and typing the value manually it works fine.

when I make a mysql_query("insert into re_rechnungsdetails set `anzahl` = 1, `rechnungstext` = 'test', `netto` = 100, `mwstsatz` = 19, `mwst` = (anzahl * netto * mwstsatz / 100)");

the row is added without any error.
Dietmar
 
Posts: 4
Joined: Mon Mar 26, 2018 1:11 pm

Re: PDO Error when using mysql_add_fun

Postby Dietmar » Mon Mar 26, 2018 1:40 pm

I have fixed this issue with two triggers in the database (a good working work around)
Dietmar
 
Posts: 4
Joined: Mon Mar 26, 2018 1:11 pm

Re: PDO Error when using mysql_add_fun

Postby Dietmar » Mon Mar 26, 2018 10:18 pm

These are the triggers, but it would be nice to fix the real problem...

DROP TRIGGER IF EXISTS `mwstadd`;

CREATE TRIGGER `mwstadd` BEFORE INSERT ON `re_rechnungsdetails`
FOR EACH ROW set NEW.mwst = (NEW.anzahl * NEW.netto * NEW.mwstsatz / 100), NEW.rechnung=(select wert from re_parameter where par='renr'),NEW.rechnungstext=REPLACE(NEW.rechnungstext,CHAR(10),'<br />') ;

DROP TRIGGER IF EXISTS `mwstupdate`;

CREATE TRIGGER `mwstupdate` BEFORE UPDATE ON `re_rechnungsdetails`
FOR EACH ROW set NEW.mwst = (NEW.anzahl * NEW.netto * NEW.mwstsatz / 100),NEW.rechnungstext=REPLACE(NEW.rechnungstext,CHAR(10),'<br />') ;
Dietmar
 
Posts: 4
Joined: Mon Mar 26, 2018 1:11 pm


Return to Open Discussion

Who is online

Users browsing this forum: No registered users and 10 guests

cron