This topic is locked
[SOLVED]

 DAL Update query error

5/8/2018 8:05:41 AM
PHPRunner General questions
U
ustunsoz author

Hi,
I am trying to update currency values on application initialization, I have created following code on After Application Initialized event :

$veri=simplexml_load_file("http://www.tcmb.gov.tr/kurlar/today.xml";);

$dolartl_s=(string)$veri->Currency[0]->BanknoteSelling;

$eurtl_s=(string)$veri->Currency[3]->BanknoteSelling;

$gbptl_s=(string)$veri->Currency[4]->BanknoteSelling;

$dolartl=(string)$veri->Currency[0]->BanknoteBuying;

$eurtl=(string)$veri->Currency[3]->BanknoteBuying;

$gbptl=(string)$veri->Currency[4]->BanknoteBuying;

$_SESSION["UsdTrl"]=$dolartl;

$_SESSION["EurTrl"]=$eurtl;

$_SESSION["GbpTrl"]=$gbptl;

$_SESSION["UsdTrl_s"]=$dolartl_s;

$_SESSION["EurTrl_s"]=$eurtl_s;

$_SESSION["GbpTrl_s"]=$gbptl_s;
global $dal;

$tblcurrencies= $dal->Table("mu_currencies");

$rs = $tblcurrencies->Query("Active='1'");

while( $data = db_fetch_array($rs) )
{

$query = "UPDATE mu_currencies SET ";
if ($currency_code == "USD"){

$query .= "`value_buy` = '$dolartl', `value_sell` = '$dolartl_s' ";

}
if ($currency_code == "EUR"){

$query .= "`value_buy` = '$eurtl', `value_sell` = '$eurtl_s' ";

}
if ($currency_code == "GBP"){

$query .= "`value_buy` = '$gbptl', `value_sell` = '$gbptl_s' ";

}
$query .= "WHERE `currency_code` = ".$data["currency_code"];

}

CustomQuery($query);


The code is not returning any syntax error while compiling. But when I am opening the web page the following error preventing to open the page:

Fatal error: 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 'WHERE currency_code = USD' at line 1 in /volume1/Web/property/connections/Connection.php on line 661


Can someone tell me what is missing??

M
mersintarim 5/8/2018

try this code
if ($currencycode == "USD"){

$query .= "value_buy ='".$dolartl."', value_sell ='".$dolartl_s."' ";

}
also where is $currencycode variable?

U
ustunsoz author 5/8/2018

Thanks for reply, but not worked out, I am still getting exactly same error as above
$currency_code is table field name
I have imlemented your suggestion as follow:
if ($currency_code == "USD"){

$query .= "value_buy ='".$dolartl."', value_sell ='".$dolartl_s."' ";

}

admin 5/8/2018

You need to print your query on the page instead of executing it. This way you can see what went wrong.

U
ustunsoz author 5/8/2018

Yes !!! One by one I have printed every variable, end up with successful code as follow.
Thanks for your time.

$veri=simplexml_load_file("http://www.tcmb.gov.tr/kurlar/today.xml";);

$dolartl_s=(string)$veri->Currency[0]->BanknoteSelling;

$eurtl_s=(string)$veri->Currency[3]->BanknoteSelling;

$gbptl_s=(string)$veri->Currency[4]->BanknoteSelling;

$dolartl=(string)$veri->Currency[0]->BanknoteBuying;

$eurtl=(string)$veri->Currency[3]->BanknoteBuying;

$gbptl=(string)$veri->Currency[4]->BanknoteBuying;

$_SESSION["UsdTrl"]=$dolartl;

$_SESSION["EurTrl"]=$eurtl;

$_SESSION["GbpTrl"]=$gbptl;

$_SESSION["UsdTrl_s"]=$dolartl_s;

$_SESSION["EurTrl_s"]=$eurtl_s;

$_SESSION["GbpTrl_s"]=$gbptl_s;
global $dal;

$tblcurrencies= $dal->Table("coolhote_property.mu_currencies");

$rs = $tblcurrencies->Query("Active='1'");

while( $data = db_fetch_array($rs) )
{

if ($data["currency_code"] == "USD"){

$query = "UPDATE mu_currencies SET value_buy ='".$_SESSION["UsdTrl"]."', value_sell ='".$_SESSION["UsdTrl_s"]."' WHERE `currency_code` = '".$data["currency_code"]."'";

}
if ($data["currency_code"] == "EUR"){

$query = "UPDATE mu_currencies SET value_buy ='".$_SESSION["EurTrl"]."', value_sell ='".$_SESSION["EurTrl_s"]."' WHERE `currency_code` = '".$data["currency_code"]."'";

}
if ($data["currency_code"] == "GBP"){

$query = "UPDATE mu_currencies SET value_buy ='".$_SESSION["GbpTrl"]."', value_sell ='".$_SESSION["GbpTrl_s"]."' WHERE `currency_code` = '".$data["currency_code"]."'";

}

CustomQuery($query);

}