Continuing with form validation
After I have some usernames in my database I'd like to check the database to see if the username the user has chosen is available and not already in use by a current user.
My thoughts are to use PHP to gather values from the database and then use a PHP if / else statement to compare these values to the one the user has chosen and see if there are any matches.
The code I've got so far is below.
Help!
<html>
<head>
<title>Check username</title>
</head>
<body>
<form action = "insert_data.php" method = "post">
<input type = "text" name = "user_name">
<input type = "submit" value = "Submit">
</form>
<?php
$con = mysql_connect("host_address","database_name","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database_name", $con);
if ($_POST["user_name"] == any value in column "username" in the database)
echo "Username not available."
else
{
echo "Username available."
}
?>
</body>
</html>