下面的代碼表示我試圖嘗試並找出行中是否存在符合條件的條件。它默認爲else語句,正確,但如果if語句似乎爲真(沒有電子郵件爲[email protected]),則不會與'if'語句一起使用,而是代碼繼續。該代碼的後半部分主要是爲了擴展情況。該行只能存在或不存在,所以我不明白爲什麼它不嚴格執行其中一個。我正在轉換爲PDO進行網站安全,這就是爲什麼不是所有的都在PDO中。如果這個問題太侷限了,我很抱歉?檢查標準下是否存在行(PDO,準備???)
$stmt = $pdo->prepare("SELECT * FROM table WHERE email = ?");
$stmt->execute(array("$email"));
$row3 = $stmt->fetch(PDO::FETCH_ASSOC);
while($row = $stmt->fetch()) {
if (! $row3) {
// Row3 doesn't exist -- this means no one in the database has this email, allow the person to join
$query = "INSERT INTO table (username, email, password, join_date) VALUES ('$username', '$email', SHA('$password1'), NOW())";
mysqli_query($dbc, $query);
$query = "SELECT * FROM table WHERE username = '$username'";
$data2 = mysqli_query($dbc, $query);
while ($row = mysqli_fetch_array($data2)) {
$recipent = '' . $row['user_id'] . '';
$query = "INSERT INTO messages (recipent, MsgTit, MsgR, MsgA, sender, time, readb, reada, MsgCon) VALUES ('$recipent', '$MsgTit', '$MsgR', '$MsgA', '$sender', NOW(), '$readb', '$reada', '$MsgCon')";
mysqli_query($dbc, $query);
// Aftermath.
echo '<p>Your new account has been successfully created. You\'re now ready to <a href="game2.php" target="_blank">log in</a>. After this you should implement basic character-details on your users profile to begin the game.</p>';
mysqli_close($dbc);
exit();
} }
else {
// An account already exists for this email, so display an error message
echo '<p class="error">An account already exists for this e-mail.</p>';
$email = "";
}
}
錯誤,如果'$ stmt-> fetch()'返回'false','while'循環已經退出,所以如果該行不存在,您將永遠不會輸入'if'語句。 'while'循環類似於'if($ row-> rowCount()> 0)' – dbf
有沒有什麼特別的原因可以混合PDO和MySQLi? –
他說他正在努力將其轉換爲按查詢查詢的PDO。我假設他不想一下子把它全部打破。他似乎還有另一個主要問題,所以混合可能不是一個大問題。 –