Bonjour,
je me permets de vous soumettre mon code car je n'arrive à poster des infos sur localhost. Pourriez-vous me le corriger?
Un grand merci pour votre aide
<?php
$bdd = new PDO('mysql:host=127.0.0.1;dbname=espace_membre', 'root', '');
if(isset($_POST['forminscription']))
{
$pseudo = htmlspecialchars($_POST['pseudo']);
$mail = htmlspecialchars($_POST['mail']);
$hashToStoreInDb = password_hash($_POST['password'], PASSWORD_DEFAULT);
$pseudolength = strlen($pseudo);
if(!empty($_POST['pseudo']) AND !empty($_POST['mail']) AND !empty($_POST['password']))
{
$pseudolength = strlen($pseudo);
if ($pseudolength <=255)
{
if (filter_var($mail, FILTER_VALIDATE_EMAIL))
{
$insertmbr = $bdd->prepare("INSERT INTO users (pseudo, mail, password) VALUES (?,?,?)");
$insertmbr->execute(array($pseudo, $mail, $password));
$erreur = "Votre compte a bien été créé !";
}
else
{
$erreur = "Sorry, that is not a valid email address";
}
}
else
{
$erreur = "User name is too long";
}
}
else
{
$erreur = "Please complete all required fields";
}
}
?>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<div align="center">
<h2>Sign Up</h2>
<h3> It’s quick and easy.</h3>
<form method="POST" action="">
<table>
<tr>
<td>
<input type="text" placeholder="User name" id="pseudo" name="pseudo" value="<?php if (isset($pseudo)) { echo $pseudo; } ?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" placeholder="Email" id="mail" name="mail" value="<?php if (isset($mail)) { echo $mail; } ?>">
</td>
</tr>
<tr>
<td>
<input type="password" placeholder="New password" id="password" name="password">
</td>
</tr>
</table>
<input type="submit" name="forminscription" value="Sign Up" />
</form>
<?php
if (isset($erreur))
{
echo '<font color="red">'.$erreur."</font>";
}
?>
</div>
</body>
</html>
je me permets de vous soumettre mon code car je n'arrive à poster des infos sur localhost. Pourriez-vous me le corriger?
Un grand merci pour votre aide
<?php
$bdd = new PDO('mysql:host=127.0.0.1;dbname=espace_membre', 'root', '');
if(isset($_POST['forminscription']))
{
$pseudo = htmlspecialchars($_POST['pseudo']);
$mail = htmlspecialchars($_POST['mail']);
$hashToStoreInDb = password_hash($_POST['password'], PASSWORD_DEFAULT);
$pseudolength = strlen($pseudo);
if(!empty($_POST['pseudo']) AND !empty($_POST['mail']) AND !empty($_POST['password']))
{
$pseudolength = strlen($pseudo);
if ($pseudolength <=255)
{
if (filter_var($mail, FILTER_VALIDATE_EMAIL))
{
$insertmbr = $bdd->prepare("INSERT INTO users (pseudo, mail, password) VALUES (?,?,?)");
$insertmbr->execute(array($pseudo, $mail, $password));
$erreur = "Votre compte a bien été créé !";
}
else
{
$erreur = "Sorry, that is not a valid email address";
}
}
else
{
$erreur = "User name is too long";
}
}
else
{
$erreur = "Please complete all required fields";
}
}
?>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
<div align="center">
<h2>Sign Up</h2>
<h3> It’s quick and easy.</h3>
<form method="POST" action="">
<table>
<tr>
<td>
<input type="text" placeholder="User name" id="pseudo" name="pseudo" value="<?php if (isset($pseudo)) { echo $pseudo; } ?>"/>
</td>
</tr>
<tr>
<td>
<input type="text" placeholder="Email" id="mail" name="mail" value="<?php if (isset($mail)) { echo $mail; } ?>">
</td>
</tr>
<tr>
<td>
<input type="password" placeholder="New password" id="password" name="password">
</td>
</tr>
</table>
<input type="submit" name="forminscription" value="Sign Up" />
</form>
<?php
if (isset($erreur))
{
echo '<font color="red">'.$erreur."</font>";
}
?>
</div>
</body>
</html>