I have a registration form in which i have a field login name. I want unique login name for every user so whenever user click a button i want to check database. If the login name entered by user is already present, i want to display an alert box asking him to try another login name. I wrote the following code.
if($login != '')
{
$query = "Select LoginName from register where LoginName='".$login."'";
$result = mysql_query($query);
if($result)
{
?>
<script type="text/javascript">
alert("Login name exist");
</script>
<?php
}
else
{
insert into database
}
}
The problem here is every time it shows me an alert for the name already exists.It never goes into the else part.
Please help me about this
first when you fetch data then count $rows array
check if count is greater that 0 then u display error msg “username already exists”
so put if condition and in else write insert data
Enjoy 🙂