2017-05-19 37 views
0

我試圖在插入數據後更新我的用戶表。當我剛剛返回所有數據但它現在是當我在Postman中運行時,給我這個錯誤消息。什麼是一般錯誤,何時以及爲什麼我們得到它? {「error」:{「text」:SQLSTATE [HY000]:General error}}

171{"error":{"text":SQLSTATE[HY000]: General error}}

這是我試圖使用苗條框架工作執行的代碼。

function add_User() 
{ 
      $response = array(); 
      $request = \Slim\Slim::getInstance()->request(); 

        $name = $request->post('name'); 
        $emailId = $request->post('emailId'); 
        $mobileNumber = $request->post('mobileNumber'); 
        $password = $request->post('password'); 
        $otp = $request->post('otp'); 
        $user_status = $request->post('user_status'); 
        $referral_code = $request->post('referral_code'); 
        $referred_by = $request->post('referred_by'); 

        $addressId=NULL; 

    $sql = "INSERT IGNORE INTO users(userId,name,emailId,mobileNumber,password,otp,user_status,referral_code,referred_by)VALUES 
    (NULL,:name,:emailId,:mobileNumber,:password,:otp,:user_status,:referral_code,:referred_by);"; 
    try 
    { 
     $db = getConnection(); 
     $stmt = $db->prepare($sql); 
     $stmt->bindParam("name", $name); 
     $stmt->bindParam("emailId", $emailId); 
     $stmt->bindParam("mobileNumber", $mobileNumber); 
     $stmt->bindParam("password", $password); 
     $stmt->bindParam("otp", $otp); 
     $stmt->bindParam("user_status", $user_status); 
     $stmt->bindParam("referral_code", $referral_code); 
     $stmt->bindParam("referred_by", $referred_by); 

      $stmt->execute(); 
      if ($stmt->rowCount()) 
     { 
      $lastId = $db->lastInsertId(); 
     echo $lastId; 
     $refCode= $referral_code.$lastId; 

      $sql ="Update Users SET referral_code = :referral_code, referred_by = :referred_by WHERE userId = :userId"; 
    try 
    { 
     $db = getConnection(); 
     $stmt = $db->prepare($sql); 
     $stmt->bindParam("userId", $lastId); 
     $stmt->bindParam("referral_code", $refCode); 
     $stmt->bindParam("referred_by", $referred_by); 

      $stmt->execute(); 
      $res = $stmt->fetchAll(PDO::FETCH_OBJ); 
      $row=count($res); 
      $db = null; 
      if ($row > 0) 
     { 
     $response["error"] = "SignUp SuccessFully"; 
      $response['userId'] = $res; 
      echoResponse(201, $response); 
     } else 
     { $response['error'] = true; 
      $response['message'] = "User Not Available"; 
      echoResponse(200, $response); 
     } 
    } catch(PDOException $e) 
    { 

     echo '{"error":{"text":'. $e->getMessage() .'}}'; 
    } 

     } else 
     { 
      $response['error'] = true; 
      $response['message'] = "Cant create User"; 
      echoResponse(200, $response); 
     } 
    } catch(PDOException $e) 
    { 

     echo '{"error":{"text":'. $e->getMessage() .'}}'; 
    } 
} 

任何幫助或支持表示讚賞。謝謝。

+1

我想你錯過了'bindParam'第一個參數中的':'。它應該看起來像這樣:'$ stmt-> bindParam(「:userId」,$ lastId);' –

+1

[PDO Error-PDOException'with message'SQLSTATE \ [HY000 \]:General error'](http:/ /stackoverflow.com/questions/20315898/pdo-error-pdoexception-with-message-sqlstatehy000-general-error) –

+0

你更新後提取什麼? –

回答

相關問題