2013-03-22 48 views
0

我有這樣的代碼:mysqli_affected_rows在PHP中插入

if(mail($to, $subject, $message, $headers)){ 
    $insert_member_sql = "INSERT INTO members (id, username) VALUES('$id', '$username')"; 
    $insert_member_res = mysqli_query($con, $insert_member_sql); 
    if(mysqli_affected_rows($con, $insert_member_res)>0){ 
    echo "1"; 
    }else{ 
    echo "0"; 
    } 
}; 

所有工作正常,與電子郵件的發送和插入信息到數據庫,但mysqli_affected_rows不工作 - 如何修改這個代碼運行查詢後回顯1?

+1

閱讀[mysqli_affected_rows(http://php.net/manual/en/mysqli.affected-rows.php)的檢查。 – Rikesh 2013-03-22 11:16:10

回答

2

改變這種

if(mysqli_affected_rows($con, $insert_member_res)>0) 

if(mysqli_affected_rows($con)>0) 

mysqli_affected_rows只需要connection link對象,但你通過查詢對象也這是問題

+1

啊,非常感謝,我現在明白了,它的工作完美 – user2184018 2013-03-22 11:19:06

+1

不會讓我接受另一個5分鐘,但我會 – user2184018 2013-03-22 11:23:25

1
if(mail($to, $subject, $message, $headers)){ 
    $insert_member_sql = "INSERT INTO members (id, username) VALUES('$id', '$username')"; 

    if (!mysql_query($insert_member_sql)){ 
    echo "1"; 
    }else{ 
    echo "0"; 
    } 
}; 
1

,或者你可以重複它

echo mysqli_affected_rows($con); 

的情況下,你要仔細當然