Page is a not externally linkable
- Code, Content, and Presentation
-- PHP Server Side Scripting
---- Form validation


Adam5000 - 1:37 pm on Oct 2, 2010 (gmt 0)


Matthew! You're a genius! The Where condition and the mysql_num_rows() function were just what was needed. You're brilliant! Applause to you!

Below is the code that worked.

<html>
<head>
<title>Username validation</title>
</head>

<body>

<form action = "username_validation.php" method = "post">
<input type = "text" name = "user_name">
<br>
<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);

$result = mysql_query("SELECT * FROM subjects WHERE username = '$_POST[user_name]'");

if (mysql_num_rows($result) > 0)

echo "Username not available";

else
{
echo "Username available";
}

mysql_close($con);
?>

</body>
</html>


Thread source:: http://www.webmasterworld.com/php/4210039.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com