1

我有这个代码:

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?

4

3 回答 3

6

改变这个

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

if(mysqli_affected_rows($con)>0)

mysqli_affected_rows只需要connection link对象,但您传递了查询对象,这也是问题所在

于 2013-03-22T11:15:07.707 回答
2

或者你可以回应它

echo mysqli_affected_rows($con);

如果您当然想仔细检查

于 2014-03-09T14:09:22.167 回答
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";
    }
};
于 2013-03-22T11:18:56.403 回答