This topic is locked

how to use mysql in combination with before record add event?

4/21/2018 8:13:16 AM
PHPRunner General questions
R
roeland author

Hi,

I am a newbie with jquery and I hope to get some help:
I have 2 tables:
producten (products)

orderinhoud (ordercontents)
in the before record add event I would like to retrieve information from the products table to insert in the orderinhoud table.
I have the following code in before add event:
---
$valueartnr = $data[Artnr];
$sql = "

SELECT productid,DSQ1,DStaf1,DSQ2,DStaf2,DSQ3,DStaf3,WSQ1,WStaf1,WSQ2,WStaf2,WSQ3,WStaf3

FROM producten

WHERE producten.productid = AND prijslijst=49

";

[color="#FF0000"]$datasql = db_fetch_array($rs);
$value1 = 300;

$value2 = ;
//$keyField="id";
if ($values["Amount"]==1)

{$values["price"] = $value1;}

else

{$values["price"] =$value2;}

return true;
---

Now the idea is that I get the value Dstaf1 from the products table when my orderinhoud.amount field contains the value '2'. Unfortunately I get a NULLvalue every time, and I don't understand what I must change here. when I fill the orderinhoud.amount field with value 1, then I get the desired result '300'
I am quite sure, that the mistake is somewhere in the red marked texts.
I hope someone can tell me what I am doing wrong.
Thanks already!

W
WilliamBDevClub member 4/23/2018

You need to change

$datasql = db_fetch_array($rs);


to

$datasql = db_fetch_array($sql);