上面的代码会起作用,if 基本上是在说 $check_user 是否高于 0,这与说如果 $check_user 不等于 0 是一样的。
我以前用过这段代码,下面是我用它做的:
这取决于您是否正在创建新用户
您必须在 Mysql_query 中连接到您的数据库,我建议使用 mysqli,而不是 mysql:
// CONNECT TO THE SERVER
$sql_con = mysqli_connect(host,username,password,dbname);
// RUN THE QUERY ON YOUR DATABASE
$check_user = mysqli_query($sql_con, "SELECT * FROM `fblogin` WHERE email = '$user_email'");
// GET NUMBER OF USERS FOUND
$check_user_num = mysqli_num_rows($check_user);
// IF NO USER EXISTS IN DATABASE DO THE FOLLOWING
if($check_user_num = 0) {
mysql_query("INSERT INTO `fblogin` (fb_id, name, email, image, postdate) VALUES ('$user_fbid', '$user_fnmae', '$user_email', '$user_image', '$now')");
} else {
// ELSE DO THIS CODE HERE (for me, I normally redirect with an error code, like the following:)
header('location:?error=exists');
}