Welcome Guest, Not a member yet? Register   Sign In
CI4 Transaction not working on me
#1

PHP Code:
When a quoted data is receivedit gives an error and the undo operation does not work.
 this page have to 17 but getting error and not rollback. 
$stoklar
=json_decode(file_get_contents('http://myjsondata.com'));
        $db->transBegin();
        foreach ($stoklar->DATA as $key => $w) {
          for ($i=0$i <count($w) ; $i++) {
            $w[$i]=htmlentities(stripslashes($w[$i]));//error was here i should add ,ENT_QUOTES, "UTF-8" i know i but wanna see transaction
          }
          $PRICE_KDV=$w[0];
          $SALEABLE_STOCK=$w[1];
          $PRODUCT_ID=$w[2];
          $PRODUCT_NAME=$w[3];
          $BARCOD=$w[4];
          $PRODUCT_CODE=$w[5];
          $PRODUCT_DETAIL=$w[6];
          $db->query("INSERT INTO stoklar (PRICE_KDV, SALEABLE_STOCK, PRODUCT_ID, PRODUCT_NAME, BARCOD, PRODUCT_CODE, PRODUCT_DETAIL)
          values ('
$PRICE_KDV','$SALEABLE_STOCK','$PRODUCT_ID','$PRODUCT_NAME','$BARCOD','$PRODUCT_CODE','$PRODUCT_DETAIL')");
        }


        if ($db->transStatus() === false) {
            $db->transRollback();
        } else {
            $db->transCommit();
        
Reply
#2

You should not be using all capital letters for your variables, they are reserved for constants
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

What error message do you get?

And you should not use htmlentities() and stripslashes() with SQL statements.
If you don't know escaping in SQL well,
see https://codeigniter4.github.io/CodeIgnit...ng-queries
Reply




Theme © iAndrew 2016 - Forum software by © MyBB