OK - in more detail 🙂
Your form looks fine!
Your php is ok, but not very secure.
$password = $_POST['password'];
It would be worth encoding this using an md5 hash so the password is not stored 'as is' in the db. Try this:
$password = md5($_POST['password']);
Your next problem is you're not really validating the username. Your current query basically says "select all the usernames from the database", but you don't really check anything.
In logic, you need to run a comparison: Select a usernname from the registration table where the username (in the table) is the same as the username that the person wants. If there is a result, then obviously the username is taken, so you can't use it, otherwise you can add it. So. In code:
//perform the query
$result = mysql_query('SELECT * FROM registration WHERE username LIKE "$user"') or die ("Error in query " mysql_error()); // add the 'or die' for error checking purposes
//if there is a result, the name must exist, so you can't do it, otherwise add it
if (mysql_num_rows($result) >0)
{
echo 'Sorry, '.$user.'is already a registered username. Please choose another';
}
else
{$query = mysql_query("INSERT INTO registration VALUES('', '$user', '$password', '$email')") or die ("Error in query " mysql_error()); // add the 'or die' for error checking purposes;
}
//Now confirm that the query happened, and if it did, say so:
if (!$query)
{
echo 'oops - it didn\'t work for some reason';
}
else
{
echo 'Thank you for registering, you may now log in';
}
Hope this makes sense!