Huy cierto que al codificar el password se necesitan 40 characters debe ser por ahi, yo tengo password varchar(18).. mi codigo para registrar usuarios es:
Código PHP:
<?php
$dbc= mysqli_connect('xxxx','xxxx','xxxx','xxxx');
if (!$dbc) {
echo'Can\'t connect to the DB server';
exit();
}
if (isset($_POST['submit'])) {
$email = mysqli_real_escape_string($dbc, trim($_POST['email']));
$password1 = mysqli_real_escape_string($dbc, trim($_POST['password1']));
$password2 = mysqli_real_escape_string($dbc, trim($_POST['password2']));
if (!empty($firstname) && !empty($lastname) && !empty($password1) && !empty($password2) && ($password1 == $password2) && preg_match("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$^", $email))
{
$query = "SELECT * FROM users WHERE email='$email'";
$data = mysqli_query($dbc, $query);
if (mysqli_num_rows($data)==0) {
$query = "INSERT INTO users (firstname, lastname, email, password) VALUES ('$firstname', '$lastname', '$email', SHA('$password1'))";
echo'inserted';
mysqli_query($dbc, $query);
echo'<p> Tu cuenta ha sido registrada. Puede acceder <a href="index.php">ACA</a></p>';
mysqli_close($dbc);
//exit the script
exit();
} else {
echo'<p class="error">An account already exists for this username. Please use a different address</p>';
$username="";
}
} else {
echo '<p class="error"> You must enter all of the sign-up data, including the desired password twice</p>';
}
}
//Close msqli connection
mysqli_close($dbc);
?>