This topic is locked
[SOLVED]

 error code 256

2/19/2018 4:02:16 AM
PHPRunner General questions
C
casuva author

Hi there,
I have a Master /Detail Table and using PHPRUNNER 9.8

I want to sum value from Detail table(arac_gorev) to Update one field of Master Table(araclar).

Master Table : field Name = toplam_km

Detail Table: Select SUM(kapanis_km-acilis_km) AS toplamkm from Detail
I wrote it;

$sum1 = DBLookup("Select SUM(kapanis_km-acilis_km) AS toplamkm from arac_gorev where FK_araclar = ".$values["id"]);

echo($sum1);

$sql_text="Update araclar set toplam_km =".$sum1." where id = ".$values["id"];

CustomQuery($sql_text);


but I have error 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 'where id = 34' at line 1
pls help me..
Best Regards..

T
thamestrader 2/19/2018

When I had error 256 it was because my SQL statement was incorrectly coded. You don't say what database you are using, but SQL database managers have the ability to execute SQL statements inactively, have you tried the Select statement on the detail table to see what format the output takes? I doubt it will be a single numeric value and there will doubtless be a column heading before it. You are relying on the DBLOOKUP formatting the output from the SQL into a single numeric value to populate the variable so it can be used in the UPDATE SQL.
Have you tried writing a simple SQL command to return all the matching records, total them with PHP and then execute the update SQL command?

admin 2/19/2018

You need to print your SQL queries on the page instead of executing them to see what exactly is wrong.

M
mersintarim 2/19/2018

try this
$sum1 = DBLookup("Select SUM(kapanis_km-acilis_km) AS toplamkm from arac_gorev where FK_araclar = '".$values["id"]."'");

C
casuva author 2/20/2018



You need to print your SQL queries on the page instead of executing them to see what exactly is wrong.


Thanks for your answers.

How can i print(monitor) sql query results?

I used to echo function but I didnt see anything..

admin 2/20/2018

Instead of

$sum1 = DBLookup("Select SUM(kapanis_km-acilis_km) AS toplamkm from arac_gorev where FK_araclar = ".$values["id"]);



use

echo("Select SUM(kapanis_km-acilis_km) AS toplamkm from arac_gorev where FK_araclar = ".$values["id"]);
M
mersintarim 2/20/2018

for print(monitor) sql query results

write a text file returned value and look at the text file

C
casuva author 2/20/2018



Instead of

$sum1 = DBLookup("Select SUM(kapanis_km-acilis_km) AS toplamkm from arac_gorev where FK_araclar = ".$values["id"]);



use

echo("Select SUM(kapanis_km-acilis_km) AS toplamkm from arac_gorev where FK_araclar = ".$values["id"]);



I use the

echo("Select SUM(kapanis_km-acilis_km) AS toplamkm from arac_gorev where FK_araclar = ".$values["id"]);


the screen message is here:
Select SUM(kapanis_km-acilis_km) AS toplamkm from arac_gorev where FK_araclar = 54
by the way , I tried mersin tarim's advice. But same result. fail..
thanks for helping..

admin 2/20/2018

Run this printed query in a tool like phpMyAdmin. Make sure it runs and it returns correct results.
Then move to the second query and do the same thing.

C
casuva author 2/21/2018

Solved
My table is crashed. Primary key was fault.

Re-created my tables and finally success.

Thanks everyone..