2012-10-02 110 views
0

我有一個函數,首先檢查,看看一行存在,如果它不插入數據。如果有任何失敗,它應該返回false。當我運行該函數並檢查返回與var_dump,它返回true。我假設數據被插入到數據庫中,但事實並非如此。爲什麼會這樣做?我的功能有問題嗎?插入到返回True,但沒有插入數據

function add_tier ($mysqli, $project_id, $tier_number, $wanted, $in_return, $limit) { 

    if ($result = $mysqli->query("SELECT COUNT(tier_id) FROM `tier` WHERE `project_id` 
    = $project_id AND `tier_number` = $tier_number")){ 

     if ($return < 1) { 

     if ($stmt = $mysqli->prepare("INSERT INTO `tier` (`project_id`, 
     `tier_number`, `wanted`, `in_return`, `limit`) VALUES (?, ?, ?, ?, ?)")){ 

     $stmt->bind_param('iissi', $project_id, $tier_number, $wanted, $in_return, 
     $limit); 

     $return = $stmt->execute(); 

     $stmt->close(); 

     return $return; 

     } else {return false;}  

     } else {return false;}    

    } else {return false;} 

} 
+0

是在這兩個領域的唯一關鍵,還是有兩個鍵,一個在每個? –

+0

'tier_id'是唯一的唯一鍵。這也是主要關鍵。 – jason328

+0

它是'auto_increment'嗎? –

回答

1

(從評論繼續)你似乎並沒有定義在該行的任何地方$return

if ($return < 1) { 
相關問題