This topic is locked
[SOLVED]

What is wrong in this query ?

12/23/2021 11:35:09 AM
PHPRunner General questions
J
Jan author

Everybody,
I have a table( table1) , with a custom button on every line. By pressing this button I adjust the values of table 1 in the table "members" . I do this with the code below that I wrote in the tab "server" :

$record = $button->getCurrentRecord();
$A = $record["table1_field_a"];
$B = $record["table1_field_b"];
$C = $record["table1_field_c"];
$sql = "Update members set field1 = $A where field2 = '$B' and field3 = '$C'";
CustomQuery($sql);
$result["txt"] = "the fields have been modified";

But the query returns an error. What is wrong in this query ?

K
kohle 12/23/2021

Hi,

after $sql=" update ....
insert this line:
echo "SQL: " . $sql;

if you run your project you will get an error (top of the browser) which shows the $sql content.
Check if the sql is correct. For mysql you can copy and test in for ex. phpmyadmin or mysql workbench

Second, use the database api in the future:

$sql = "Update members set field1 = " . $A . " where field2 = '" . $B . "' and field3 = '". $C . "'";
DB::Exec($sql);

rgs
J

J
Jan author 12/23/2021

Thank you for your answer. Of course in the browser I can see the error message at the top. When I run the query in phpmyadmin it works fine, also in an event (eg after addrecords ) But not in the server tab of a custom button.

this message appears in the browser:

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version ...
K
kohle 12/23/2021

Hi,

can you send the sql from the error message, or whole line. (echo $sql)

Is field1 a numeric value in the database?

rgs
J.

J
Jan author 12/23/2021

Field a is a "double" field
Field b and c are "varchar" fields

In reality the field names are unclear because they are names in Dutch

J
Jan author 12/24/2021

It seems that the server event can create a query with only one variable. So I solved this in a different way. thanks