I´m trying to insert data into database but for some reason the code doesn´t work. Here is form i´m using.
<form id="registration" method="post" action="index.php" style="display: none;">
<label for="username" class="username">
Username
</label>
<input type="text" name="r-username" id="r-username" placeholder="Username" required/>
<label for="password">
Password
</label>
<input type="password" name="password" id="password" placeholder="Password" required/>
<label for="check_password" class="check_password">
Password Check
</label>
<input type="password" name="check-password" id="check_password" placeholder="Password again" required/>
<label for="e-mail">
E-mail
</label>
<input type="email" name="e-mail" id="e-mail" placeholder="E-mail" required/>
<label for="check-e-mail" class="check_email">
E-mail Check
</label>
<input type="email" name="check-e-mail" id="check-e-mail" placeholder="E-mail again" required/>
<input type="submit" name="submit" class="submit" value="Register"/>
</form>
And here is PHP code:
if(isset($_POST['r-username']))
{
$name=$_POST['r-username'];
$pass=$_POST['password'];
$passcheck=$_POST['check-password'];
$mail=$_POST['e-mail'];
$mailcheck=$_POST['check-e-mail'];
if($name==''||$pass==''||$passcheck==''||$mail==''||$mailcheck=='')
{
echo "<script type='text/javascript'>alert('Field must be filled.');</script>";
}
elseif(strlen($pass)<=6)
{
echo "<script type='text/javascript'>alert('Password is too short.');</script>";
}
elseif(strlen($pass)>=20)
{
echo "<script type='text/javascript'>alert('Password is too long.');</script>";
}
elseif($pass!==$passcheck)
{
echo "<script type='text/javascript'>alert('Passwords must be same.');</script>";
}
elseif($mail!==$mailcheck)
{
echo "<script type='text/javascript'>alert('Emails must be same.');</script>";
}
else
{
$sql5='INSERT INTO user(user_name,password,joined,user_email) VALUES(:username,:password,Now(),:email)';
$query1=$db->prepare($sql5);
$result=$query1->execute(array( ":username" => $name,
":password" => $pass,
":email" => $mail
));
if($result)
{
echo "<script type='text/javascript'>alert('Inserted.');</script>";
}
else
{
echo "<script type='text/javascript'>alert('ERROR.');</script>";
}
}
}
Code runs but id doesn´t do anything. It just reloads page echoes message ERROR and inserts no data into database. Sorry for my bad english and thanks for possible answers :).