尝试访问bool类型PHP值上的数组偏移量



当我想注册一个新用户时,出现错误

注意:试图访问p:xampphtdocsBTPv4register.php中类型bool值的数组偏移

注意:试图访问p:xampphtdocsBTPv4register.php中类型bool值的数组偏移

仍然,这一切都工作,用户创建但我想修复它,我不知道哪里错了

<?php
require_once 'include/database.php';
if(isset($_POST['btn_register'])){
$fname = strip_tags($_REQUEST['fname']);
$lname = strip_tags($_REQUEST['lname']);
$email = strip_tags($_REQUEST['email']);
$phone = strip_tags($_REQUEST['phone']);
$password = strip_tags($_REQUEST['password']);
$rpassword = strip_tags($_REQUEST['passwordrepet']);
if(empty($fname)){
$errorMsg[] = "Proszę podać imię";
}else if(empty($lname)){
$errorMsg[] = "Proszę podać nazwisko";
}else if(empty($email)){
$errorMsg[] = "Proszę podać adres e-mail";
}else if(empty($password)){
$errorMsg[] = "Proszę podać hasło";
}else if(empty($rpassword)){
$errorMsg[] = "Należy ponownie podać hasło";
}else if(strlen($password) < 6){
$errorMsg[] = "Hasło musi zawierać conajmniej 6 znaków";
}else if($password != $rpassword){
$errorMsg[] = "Hasła nie są takie same";
}else{
try{
$select_stmt = $db->prepare("SELECT email, phone FROM user WHERE email=:email OR phone=:phone");
$select_stmt->bindValue(':email', $email, PDO::PARAM_STR);
$select_stmt->bindValue(':phone', $phone, PDO::PARAM_STR);
$select_stmt->execute();
$row = $select_stmt->fetch(PDO::FETCH_ASSOC);

if($row['email'] == $email){
$errorMsg[] = "Adres e-mail jest już zajęty";
}else if($row['phone'] == $phone){
$errorMsg[] = "Numer telefonu został juz podany do innego konta";
}else if(!isset($errorMsg)){
$new_password = password_hash($password, PASSWORD_DEFAULT);
$insert_stmt = $db->prepare("INSERT INTO user (fname, lname, email, phone, password) VALUES (:fname, :lname, :email, :phone, :password)");
if($insert_stmt->execute(array( ':fname' =>$fname,
':lname' =>$lname,
':email' =>$email,
':phone' =>$phone,
':password' => $new_password))){
$registerMsg = "Udało sie zarejestrować";
}
}
}catch(PDOException $e){
echo $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<title>Best Trip Partner Register</title>
<!-- Custom fonts for this template-->
<link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Nunito:200,200i,300,300i,400,400i,600,600i,700,700i,800,800i,900,900i" rel="stylesheet">
<!-- Custom styles for this template-->
<link href="css/main.css" rel="stylesheet">
</head>
<body class="bg-gradient-primary">
<div class="container">
<div class="card o-hidden border-0 shadow-lg my-5">
<div class="card-body p-0">
<!-- Nested Row within Card Body -->
<div class="row">
<div class="col-lg-5 d-none d-lg-block bg-register-image"></div>
<div class="col-lg-7">
<div class="p-5">
<div class="text-center">
<h1 class="h4 text-gray-900 mb-4">Utwórz konto</h1>
</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" class="user">
<div class="form-group row">
<div class="col-sm-6 mb-3 mb-sm-0">
<input type="text" name="fname" class="form-control form-control-user" id="exampleFirstName" placeholder="Imię">
</div>
<div class="col-sm-6">
<input type="text" name="lname" class="form-control form-control-user" id="exampleLastName" placeholder="Nazwisko">
</div>
</div>
<div class="form-group row">
<div class="col-sm-6 mb-3 mb-sm-0">
<input type="email" name="email" class="form-control form-control-user" id="exampleInputEmail" placeholder="Adres e-mail">
</div>
<div class="col-sm-6">
<input type="phone" name="phone" class="form-control form-control-user" id="exampleInputPhone" placeholder="Numer telefonu">
</div>
</div>
<div class="form-group row">
<div class="col-sm-6 mb-3 mb-sm-0">
<input type="password" name="password" class="form-control form-control-user" id="exampleInputPassword" placeholder="Hasło">
</div>
<div class="col-sm-6">
<input type="password" name="passwordrepet" class="form-control form-control-user" id="exampleRepeatPassword" placeholder="Powtórz hasło">
</div>
</div>
<?php
print_r($row);
if(isset($errorMsg)){
foreach($errorMsg as $error){
?>
<div class="alert alert-danger">
<strong><?php echo $error; ?></strong>
</div>
<?php
}
}
if(isset($registerMsg)){
?>
<div class="alert alert-success">
<strong><?php echo $registerMsg; ?></strong>
</div>
<?php
}
?>
<button type="submit" name="btn_register" class="btn btn-primary btn-user btn-block">Zarejestruj się</button>
</form>
<hr>
<div class="text-center">
<a class="small" href="forgot-password.php">Zapomniałeś hasła?</a>
</div>
<div class="text-center">
<a class="small" href="login.php">Masz już konto? Zaloguj się!</a>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript-->
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Core plugin JavaScript-->
<script src="vendor/jquery-easing/jquery.easing.min.js"></script>
<!-- Custom scripts for all pages-->
<script src="js/sb-admin-2.min.js"></script>
</body>
</html>

请使用array_key_exists()函数检查变量中是否存在key email和phone。类似…

if (array_key_exists("email", $row)) {
if ($row['email'] == $email) {
$errorMsg[] = "Adres e-mail jest już zajęty";
}
}

相关内容

  • 没有找到相关文章

最新更新