每次我離開任何第一次未填充的文本框時,它將被註冊到數據庫,就像我將所有文本框留空一樣,但是當您第二次(兩者中的任何一個)執行時,那將是彈出警告框的時間......我不知道該怎麼做。 請幫助我。 這裏是我的代碼:註冊驗證
<?php
ini_set('display_errors', 0);
$email= $_POST['email'];
$user= $_POST['user'];
$password= $_POST['password'];
$image =($_FILES['image']['name']);
$submit= $_POST['submit'];
if (empty($email) || empty($password) || empty($user))
{
echo "<script type='text/javascript'>
alert('You did not complete all of the required fields');
window.location='blah2.php';
</script>";
}
if(isset($submit))
{
$con = mysqli_connect("localhost", "root", "", "top")
or die('error in connection'.mysqli_connect_error());
$q = "SELECT username , email FROM registries WHERE username = ? OR email = ?";
$stmt = mysqli_prepare ($con, $q);
mysqli_stmt_bind_param($stmt, 'ss', $user, $email);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $user , $email);
mysqli_stmt_store_result($stmt);
$result = mysqli_stmt_num_rows($stmt);
if($result > 0)
{
echo "<script type='text/javascript'>
alert('Email address or Username is already taken. Please pick another one.');
window.location='blah2.php';
</script>";
}
else
{
$q="INSERT INTO registries VALUES (?,?,?,?)";
$stmt = mysqli_prepare($con, $q);
move_uploaded_file($_FILES["image"]["tmp_name"],"uploads/" . $_FILES["image"]["name"]);
mysqli_stmt_bind_param($stmt, 'ssss', $email, $user, $password, $image);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
mysqli_stmt_close($stmt);
header('Location: blah.php');
}
}
這個問題有點不清楚,你可以舉一個更好的例子(關於現在發生了什麼,以及預期的功能應該是什麼)? – Tyler
@TylerAndFriends如果我嘗試按下「完成」按鈕而不填滿文本框或第一次嘗試的所有文本框,它將註冊到數據庫而不是彈出警告框並告訴用戶他們將文本框留空。但是當我再次重複它的時候,那是代碼正常工作的時間。我想知道如何使這個代碼正常工作。 – user2863596