2010-07-21 136 views
0
$sql="INSERT INTO wp_comments (comment_post_ID, comment_author, comment_date, comment_content, user_id) 
       VALUES 
       ('$qID', '$author', '$dro', '$content', '$_SESSION[user_id]')"; 

      $result = mysql_query($sql); 
      die(last_insert_id()); 

當我運行此代碼時,我只看到白色屏幕,所以last_insert_id()似乎沒有返回任何值...我做錯了什麼?mysql_insert_id不返回任何東西

+0

使用mysql_error查看錯誤 – 2010-07-21 14:28:01

回答

1

從上出口PHP手冊(管芯是出口的別名):

如果狀態是一個字符串,這個函數 打印狀態剛剛退出之前。

如果status是一個整數,那麼將使用該值 作爲退出狀態,並且不打印 。退出狀態應爲 ,範圍爲0到254,退出狀態 255由PHP保留,不應使用 。狀態0用於 成功終止程序。

如果last_insert_id()返回一個整數,它將不會被打印。

順便說一句,last_insert_id不是一個內置的PHP函數。你也應該確保你正在使用正確的功能。

試試這個(假設該LAST_INSERT_ID函數定義):

print last_insert_id(); 
exit(); 
0

你需要運行last_insert_id爲PHP內定期MySQL查詢。事情是這樣的:

$result = mysql_query("SELECT LAST_INSERT_ID() FROM wp_comments"); 
1

如前所述,檢查mysql_error()mysql_errno()第一。捕獲它們的好方法是:

if (mysql_errno()==0) { 
    // all was good 
    $last_insert_id = mysql_insert_id(); 
} 
else { 
    // error occurred 
    echo mysql_error(); 
}