- 65
- 9
- CPU
- Intel® Pentium® G4560
- Scheda Madre
- H110-DGS R3.0
- HDD
- HDD 1TB
- RAM
- 8
- GPU
- 970 GTX
- PSU
- Corsair VS650
- Net
- 10 download e 2 uploads
- OS
- Windows 10
salve, ho bisogno di aiuto ho programmato dei file html nel server mi fanno un errore grave, l' errore è il seguente Fatal error: Uncaught Error: Call to a member function bind_param() on boolean in /storage/ssd2/891/11853891/public_html/controllers/authController.php:61 Stack trace: #0 /storage/ssd2/891/11853891/public_html/registrazione.php(1): require_once() #1 {main} thrown in /storage/ssd2/891/11853891/public_html/controllers/authController.php on line 61 non riesco a trovare questo errore sembra tutto corretto, grazie spero in un aiuto. il codice authcontroller.php è questo:
PHP:
<?php
session_start();
require 'config/db.php';
$errors = array();
$nomeutente = "";
$email = "";
// se l'utente fa clic sul pulsante Iscriviti
if (isset($_POST['registrazione-btn'])) {
$nomeutente = $_POST['nomeutente'];
$email = $_POST['email'];
$password = $_POST['password'];
$passwordConf = $_POST['passwordConf'];
// validazione
if(empty($nomeutente)) {
$errors['nomeutente'] = "Nome Utente richiesto";
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors['email'] = "indirizzo Email non valido";
}
if(empty($email)) {
$errors['email'] = "Email richiesta";
}
if(empty($password)) {
$errors['password'] = "password richiesta";
}
if ($password !== $passwordConf) {
$errors['password'] = "Le due password non corrispondono";
}
$emailQuery = "SELECT * FROM users WHERE email=? LIMIT 1";
$stmt = $conn->prepare($emailQuery);
$stmt->bind_param('s', $email);
$stmt->execute();
$result = $stmt->get_result();
$userCount = $result->num_rows;
$stmt->close();
if ($userCount < 0) {
$errors['email'] = "Email già esistente ";
}
if (count($errors) === 0) {
$password = password_hash($password, PASSWORD_DEFAULT);
$token = bin2hex(random_bytes(50));
$verificata = false;
$sql = "INSERT INTO users (nomeutente, email, verificata, token, password) VALUES (?, ?, ?, ?, ?,)";
$stmt = $conn->prepare($sql);
$stmt->bind_param('ssbss', $nomeutente, $email, $verificata, $token, $password);
if ($stmt->execute()) {
// Accesso utente
$user_id = $conn->insert_id;
$_SESSION['id'] = $user_id;
$_SESSION['nomeutente'] = $nomeutente;
$_SESSION['email'] = $email;
$_SESSION['verificata'] = $verificata;
// set flash message
$_SESSION['message'] = "ora sei accesso!";
$_SESSION['alert class'] = "alert-success";
header('location: index.php');
exit();
} else {
$errors['db_error'] = "Database error: impossibile registrarsi";
}
}
}
invece registrazione.php è questo codice:
<?php require_once 'controllers/authController.php'; ?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<!-- Bootstrap 4 CSS -->
<link rel="stylesheet" href="login.css"
<link rel="stylesheet" href="style.css">
<style>
img[alt="[URL="http://www.000webhost.com"]www.000webhost.com[/URL]"]{display:none;}
</style>
<title>Registrazione</title>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-md-4.offset-md-4 form-div">
<form action="registrazione.php" method="post">
<h3 class="text-center">Registrati</h3>
<?php if(count($errors) > 0): ?>
<div class="alert alert-danger">
<?php foreach($errors as $error): ?>
<li><?php echo $error; ?></li>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="form-group">
<label for="nomeutente">Nome Utente</label>
<input type="text" name="nomeutente" value="<?php echo $nomeutente; ?>" class="form control form-control-lg">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" value="<?php echo $email; ?>" class="form control form-control-lg">
</div>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" name="password" class="form control form-control-lg">
</div>
<div class="form-group">
<label for="passwordConf">Conferma La Password</label>
<input type="password" name="passwordConf" class="form control form-control-lg">
</div>
<div class="form-group">
<button type="sottoscriviti" name="registrazione-btn" class="btn btn-primary btn-block btn-lg">Iscriviti</button>
</div>
<p class="text-center">sei già un membro? <a href="accesso.php">Accedi</a></p>
</form>
</body>
</html>
Ultima modifica da un moderatore: