Aled | php qui se co pas a myslq enfin je crois

Fermé
dmkfoundation Messages postés 5 Date d'inscription mercredi 21 juillet 2021 Statut Membre Dernière intervention 22 juillet 2021 - 22 juil. 2021 à 02:00
dmkfoundation Messages postés 5 Date d'inscription mercredi 21 juillet 2021 Statut Membre Dernière intervention 22 juillet 2021 - 22 juil. 2021 à 18:48
Salut, pouriez vous m'aider, quand je crée un compte, il rajoute pas le compte dans la base de donnée.
<?php
// Change this to your connection info.
$DATABASE_HOST = 'sql110.epizy.com';
$DATABASE_USER = 'epiz_29202460';
$DATABASE_PASS = 'confidentiel';
$DATABASE_NAME = 'epiz_29202460_user';
// Try and connect using the info above.
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if (mysqli_connect_errno()) {
	// If there is an error with the connection, stop the script and display the error.
	exit('Failed to connect to MySQL: ' . mysqli_connect_error());
}
// Now we check if the data was submitted, isset() function will check if the data exists.
if (!isset($_POST['username'], $_POST['password'], $_POST['email'], $_POST['name'])) {
	// Could not get the data that should have been sent.
	exit('Please complete the registration form!');
}
// Make sure the submitted registration values are not empty.
if (empty($_POST['username']) || empty($_POST['password']) || empty($_POST['email']) || empty($_POST['name'])) {
	// One or more values are empty.
	exit('Please complete the registration form');
}
// We need to check if the account with that username exists.
if ($stmt = $con->prepare('SELECT id, password FROM accounts WHERE username = ?')) {
	// Bind parameters (s = string, i = int, b = blob, etc), hash the password using the PHP password_hash function.
	$stmt->bind_param('s', $_POST['username']);
	$stmt->execute();
	$stmt->store_result();
	// Store the result so we can check if the account exists in the database.
	if ($stmt->num_rows > 0) {
		// Username already exists
		echo 'Username exists, please choose another!';
	} else {
		// Insert new account
        // Username doesnt exists, insert new account
if ($stmt = $con->prepare('INSERT INTO accounts (username, password, email, name) VALUES (?, ?, ?, ?)')) {
	// We do not want to expose passwords in our database, so hash the password and use password_verify when a user logs in.
	$password = password_hash($_POST['password'], PASSWORD_DEFAULT);
	$stmt->bind_param('sss', $_POST['username'], $password, $_POST['email'], $_POST['name']);
	$stmt->execute();
	echo 'You have successfully registered, you can now login!';
    
} else {
	// Something is wrong with the sql statement, check to make sure accounts table exists with all 3 fields.
	echo 'Could not prepare statement!';
}
	}
	$stmt->close();
} else {
	// Something is wrong with the sql statement, check to make sure accounts table exists with all 3 fields.
	echo 'Could not prepare statement!';
}
$con->close();
?>
A voir également:

1 réponse

Pitet Messages postés 2826 Date d'inscription lundi 11 février 2013 Statut Membre Dernière intervention 21 juillet 2022 524
22 juil. 2021 à 10:23
Bonjour,

Est-ce que tu as un message d'erreur ? Si oui lequel ?

Plus d'infos sur la gestion des erreurs PHP : https://forums.commentcamarche.net/forum/affich-37584947-php-gestion-des-erreurs-debogage-et-ecriture-du-code
0
dmkfoundation Messages postés 5 Date d'inscription mercredi 21 juillet 2021 Statut Membre Dernière intervention 22 juillet 2021
22 juil. 2021 à 14:50
J'ai aucun message d'eurreur.
0
Pitet Messages postés 2826 Date d'inscription lundi 11 février 2013 Statut Membre Dernière intervention 21 juillet 2022 524 > dmkfoundation Messages postés 5 Date d'inscription mercredi 21 juillet 2021 Statut Membre Dernière intervention 22 juillet 2021
22 juil. 2021 à 14:58
Dans ce cas pas de problème, tout fonctionne !

As tu bien activer l'affichage des erreurs comme indiqué sur le lien de mon premier message ?
Qu'est-ce qui est affiché sur la page lors de la création d'un compte ?
0
dmkfoundation Messages postés 5 Date d'inscription mercredi 21 juillet 2021 Statut Membre Dernière intervention 22 juillet 2021 > Pitet Messages postés 2826 Date d'inscription lundi 11 février 2013 Statut Membre Dernière intervention 21 juillet 2022
22 juil. 2021 à 18:48
Sa dit que le compte à été créé.
0