My tabla se llama "users" y el orden de las columnas es (password, username, firstname...
Ver //*************************** en el codigo
Código PHP:
<?php
//require_once('configuration.php');
//Connect to the database
$dbc= mysqli_connect('localhost','root','root','chic');
//See if the connection to the DB was succesful
if (!$dbc) {
echo'Can\'t connect to the DB server';
exit();
}
//If submit is set it up, or "used/pressed" then continue
if (isset($_POST['submit'])) {
//Making sure that all the user-entered data is cleaned up from spaces or characters
$username = mysqli_real_escape_string($dbc, trim($_POST['username']));
$password1 = mysqli_real_escape_string($dbc, trim($_POST['password1']));
$password2 = mysqli_real_escape_string($dbc, trim($_POST['password2']));
//Making sure the fields are not empty and that password1 is equal password2
if (!empty($username) && !empty($password1) && !empty($password2) && ($password1 == $password2))
{
//make sure nobody is registered using this username
$query = "SELECT * FROM users WHERE username='$username'";
$data = mysqli_query($dbc, $query);
if (mysqli_num_rows($data)==0) {
//*********************************The username is unique, so insert the data into the database
$query = "INSERT INTO users (password, username) VALUES (SHA('$password1'), '$username', NOW())";
echo'A esta altura el INSERT INTO ya tiene que haberse procesado';
//This would process the new query
mysqli_query($dbc, $query);
//Confirm success with the user
echo'<p> Your new account has been successfully created. You\'re now ready to log in <a href="index.php">HERE</a></p>';
mysqli_close($dbc);
//exit the script
exit();
//Applys to third If on line 34
} else {
//An account already exists for this username, so display an error message
echo'<p class="error">An account already exists for this username. Please use a different address</p>';
//Clear the $username variable so that the form field is cleared.
$username="";
}
//Applys to second If on line 27
} else {
//One of more of the form fields are empty, so display an error message.
echo '<p class="error"> You must enter all of the sign-up data, including the desired password twice</p>';
}
//Close first If on line 18
}
//Close msqli connection
mysqli_close($dbc);
?>