2017-08-01 120 views
-1

我插入數據到表中,並使用PDO更新我的數據庫中的表,我承認這不是最瞭解的。PDO查詢沒有插入,也沒有拋出錯誤

我正在使用過去多次使用過的語句,但由於某種原因,這次它不適用於準備好的插入語句。它只適用於更新聲明。

聲明如下:

 error_reporting(E_ALL); 
     ini_set('display_errors',1); 
     //fetching error 
     $stmt = $pdo->prepare("INSERT INTO tb_beli (username, bank, norek, nama, ec, bitcoin, perfectmoney, fasapay, paket, saldo, amountbtc, phone, email, status, referer, iddb, date, ip, exp, unik,idph, upline, token) 
     VALUES(:username, :bank, :norek, :nama, :ec, :bitcoin, :perfectmoney, :fasapay, :paket, :saldo, :amountbtc, :phone, :email, :status, :referer, :iddb, :date, :ip, :exp, :unik, :idph, :upline, :token)"); 
     $stmt ->execute(array(':username' => $kuriree, ':bank' => $bankee, ':norek' => $norekee, ':nama' => $namaee, ':ec' => $matauang, ':bitcoin' => $bitcoinee, ':perfectmoney' => $pmee, ':fasapay' => $fasapayee, ':paket' => $paketzee, ':saldo' => $surabayae, ':amountbtc' => $convertbtc2, ':phone' => $phoneee, ':email' => $emailee, ':status' => $status1,':referer' => $kurirz,':iddb' => $idnyaz,':date' => $skrg,':ip' =>$laip ,':exp' => $exp,':unik' => $unikee,':idph' => $idnyaee,':upline' => $mangkosim,':token' => $unikeef)); 
     // 
     //echo done 
     $stmt = $pdo->prepare("INSERT INTO tb_jual (username, bank, norek, nama, ec, bitcoin, perfectmoney, fasapay, paket, saldo, amountbtc, phone, email, status, date, ip, idgh, token) 
     VALUES(:username, :bank, :norek, :nama, :ec, :bitcoin, :perfectmoney, :fasapay, :paket, :saldo, :amountbtc, :phone, :email, :status, :date, :ip, :idgh, :token)"); 
     $stmt ->execute(array(':username' => $kurirz, ':bank' => $bankeem, ':norek' => $norekeem, ':nama' => $namaeem, ':ec' => $matauang, ':bitcoin' => $bitcoineem, ':perfectmoney' => $pmeem, ':fasapay' => $fasapayeem, ':paket' => $paketzee, ':saldo' => $surabayae, ':amountbtc' => $convertbtc2, ':phone' => $phoneeem, ':email' => $emaileem, ':status' => $status2, ':date' => $skrg, ':ip' => $laip, ':idgh' => $idnyaz, ':token' => $unikeef)); 
     // 
     //echo done 
     $stmt= $pdo->prepare("UPDATE tb_ph SET saldo= (saldo - :saldo) where id=:id "); 
     $stmt ->execute(array(':id' => $idnyaee, ':saldo' => $surabayae)); 
     // 
     //echo done 
     $stmt= $pdo->prepare("UPDATE tb_gh SET saldo= (saldo - :saldo) where id=:id"); 
     $stmt->execute(array(':id' => $idnyaz , ':saldo' => $surabayae)); 
     //echo done 
     //array ends here for checkup 

但不幸的是,這是永遠返回是TRUE沒有任何數據到數據庫表。只是更新,這應該是插入到我的數據庫後完成的。

我已經嘗試了每個組合的更改,我可以想到的聲明,但我仍然處於虧損狀態。它也不會返回任何錯誤。

+0

在interweb帽=大喊 – rtfm

+1

你不這樣做實際上並不檢查錯誤 –

+0

兩個插入失敗? – chris85

回答

2

只需刪除冒號(:)在執行語句如下,

下面的代碼爲我工作(加入測試值)。

$statement = $link->prepare("INSERT INTO tb_beli(username, bank, norek, nama, ec, bitcoin, perfectmoney, fasapay, paket, saldo, amountbtc, phone, email, status, referer, iddb, date, ip, exp, unik,idph, upline, token) 
VALUES(:username, :bank, :norek, :nama, :ec, :bitcoin, :perfectmoney, :fasapay, :paket, :saldo, :amountbtc, :phone, :email, :status, :referer, :iddb, :date, :ip, :exp, :unik, :idph, :upline, :token)"); 

$kuriree = 'bb'; 
$bankee = 'cc'; 
$norekee = 'cc'; 
$namaee = 'cc'; 
$matauang = 'cc'; 
$bitcoinee = 'cc'; 
$pmee = 'cc'; 
$fasapayee = 'cc'; 
$paketzee = 'cc'; 
$surabayae = 'cc'; 
$convertbtc2 = 'cc'; 
$phoneee = 'cc'; 
$emailee = 'cc'; 
$status1 = 'cc'; 
$kurirz = 'cc'; 
$idnyaz = 'cc'; 
$skrg = 'cc'; 
$laip = 'cc'; 
$exp = 'cc'; 
$unikee = 'cc'; 
$idnyaee = 'cc'; 
$mangkosim = 'cc'; 
$unikeef = 'aa'; 

$ret = $statement->execute(array('username' => $kuriree, 'bank' => $bankee, 'norek' => $norekee, 'nama' => $namaee, 'ec' => $matauang, 'bitcoin' => $bitcoinee, 'perfectmoney' => $pmee, 'fasapay' => $fasapayee, 'paket' => $paketzee, 'saldo' => $surabayae, 'amountbtc' => $convertbtc2, 'phone' => $phoneee, 'email' => $emailee, 'status' => $status1,'referer' => $kurirz,'iddb' => $idnyaz,'date' => $skrg,'ip' =>$laip ,'exp' => $exp,'unik' => $unikee,'idph' => $idnyaee,'upline' => $mangkosim,'token' => $unikeef)); 

if($ret) 
    print '1 row Inserted'; 
else 
    print 'Error in Inserting'; 
+0

感謝您的幫助。但仍然沒有解決辦法。只有更新的方面完美。 –

+0

插入不工作? (你有你給ID爲主鍵,並設置爲自動增量?) –

1

它看起來像要覆蓋$stmt變量的每次因此只有一個$stmt將工作,最後一個是更新可能會奏效。

嘗試,這可能是你在尋找什麼:

<?php 
error_reporting(E_ALL); 
ini_set('display_errors', 1); 

try { 

    $pdo->beginTransaction(); 

    //fetching error 
    if ($stmt = $pdo->prepare("INSERT INTO tb_beli (username, bank, norek, nama, ec, bitcoin, perfectmoney, fasapay, paket, saldo, amountbtc, phone, email, status, referer, iddb, date, ip, exp, unik,idph, upline, token) 
     VALUES(:username, :bank, :norek, :nama, :ec, :bitcoin, :perfectmoney, :fasapay, :paket, :saldo, :amountbtc, :phone, :email, :status, :referer, :iddb, :date, :ip, :exp, :unik, :idph, :upline, :token)")) { 

     if (!$stmt->execute(array(
      ':username' => $kuriree, 
      ':bank' => $bankee, 
      ':norek' => $norekee, 
      ':nama' => $namaee, 
      ':ec' => $matauang, 
      ':bitcoin' => $bitcoinee, 
      ':perfectmoney' => $pmee, 
      ':fasapay' => $fasapayee, 
      ':paket' => $paketzee, 
      ':saldo' => $surabayae, 
      ':amountbtc' => $convertbtc2, 
      ':phone' => $phoneee, 
      ':email' => $emailee, 
      ':status' => $status1, 
      ':referer' => $kurirz, 
      ':iddb' => $idnyaz, 
      ':date' => $skrg, 
      ':ip' => $laip, 
      ':exp' => $exp, 
      ':unik' => $unikee, 
      ':idph' => $idnyaee, 
      ':upline' => $mangkosim, 
      ':token' => $unikeef 
     ))) { 


      $error = $stmt->errorInfo(); 
      throw new Exception($error); 
     } 

     if ($stmt_two = $pdo->prepare("INSERT INTO tb_jual (username, bank, norek, nama, ec, bitcoin, perfectmoney, fasapay, paket, saldo, amountbtc, phone, email, status, date, ip, idgh, token) 
     VALUES(:username, :bank, :norek, :nama, :ec, :bitcoin, :perfectmoney, :fasapay, :paket, :saldo, :amountbtc, :phone, :email, :status, :date, :ip, :idgh, :token)")) { 

      if (!$stmt_two->execute(array(
       ':username' => $kurirz, 
       ':bank' => $bankeem, 
       ':norek' => $norekeem, 
       ':nama' => $namaeem, 
       ':ec' => $matauang, 
       ':bitcoin' => $bitcoineem, 
       ':perfectmoney' => $pmeem, 
       ':fasapay' => $fasapayeem, 
       ':paket' => $paketzee, 
       ':saldo' => $surabayae, 
       ':amountbtc' => $convertbtc2, 
       ':phone' => $phoneeem, 
       ':email' => $emaileem, 
       ':status' => $status2, 
       ':date' => $skrg, 
       ':ip' => $laip, 
       ':idgh' => $idnyaz, 
       ':token' => $unikeef 
      ))) { 


       throw new Exception($stmt_two->errorInfo()); 
      } 
     } 

     if ($stmt_three = $pdo->prepare("UPDATE tb_ph SET saldo= (saldo - :saldo) where id=:id ")) { 

      if (!$stmt_three->execute(array(
       ':id' => $idnyaee, 
       ':saldo' => $surabayae 
      ))) { 

       throw new Exception($stmt_three->errorInfo()); 
      } 
     } 

     if ($stmt_four->$pdo->prepare("UPDATE tb_gh SET saldo= (saldo - :saldo) where id=:id")) { 

      if (!$stmt_four->execute(array(
       ':id' => $idnyaz, 
       ':saldo' => $surabayae 
      ))) { 

       throw new Exception($stmt_four->errorInfo()); 
      } 
     } 

    } 

    if ($pdo->commit()) { 
     echo "Data Proccessing complete"; 
    } else { 
     throw new Exception('Transaction commit failed.'); 
    } 
} 
catch (Exception $e) { 
    try { 
     // something went wrong, we have to rollback 
     $pdo->rollback(); 
     // and display the error message 
     echo "error : " . $e->getMessage(); 
    } 
    catch (Exception $f) { 
     // and display the error message 
     echo "error" . $f->getMessage(); 
    } 
} 

?> 
+0

試過這個,但現在即使在出現錯誤報告時仍顯示空白屏幕 –

+0

檢查您的錯誤日誌它說什麼@LegiSmith –

相關問題