为什么我的Mysqli没有更新?相反它INSERT一个新用户甚至强硬它的uniqis $ FUID,有什么可以做的,我的表有一个自动增量列或什么?我做错了什么? (对不起,如果它看起来像是一个基本的愚蠢问题,我只是在学习,并且因为太多时间试图解决这个问题而陷入困境)
代码:
// Create connection.
$conn = mysqli_connect($servername, $username, $password, $dbusers);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
/*---- check for existing user ----*/
$sql=mysqli_query("SELECT * FROM Users WHERE Fuid $fuid");
//Uniq ID already exists
if(mysqli_num_rows($sql) == 0) // tryed $check = mysqli_num_rows( $check);
//if (empty($check))
{
$jkey = md5(microtime().rand()); //create random key for arduino connecton authentication
$sql = "INSERT INTO Users (Fuid,Ffname,Femail,JKey,Gender) VALUES ('$fbid','$fbfullname','$femail','$jkey','$gender')";
if (mysqli_query($conn, $sql)) { echo "OK - user ".$fbid." email: ".$femail; }
else { echo "Fail: " . $sql . "<br>" . mysqli_error($conn); }
/*---- existing user, update user data into db ----*/
}
else { // If Returned user . update the user record
$sql = "UPDATE Users SET Ffname='$ffname', Femail='$femail' where Fuid = $fuid ";
if (mysqli_query($conn, $sql)) { echo "OK - user ".$fbid." email: ".$femail; }
else { echo "Fail: " . $sql . "<br>" . mysqli_error($conn); }
//mysqli_query($sql);
}