i have a problem in this code , this code must check the users in the db first then if the user does not exist it will make a record in the db and if the user exist it will return back Username is already in use , my problem is that every time i enter a user name even it is in the db it makes a new user with the same username
PHP Code:$sql = mysql_query("SELECT * FROM login");
$flag=0;
while ($r = mysql_fetch_array($sql))
{
if ($r['user'] == $_POST['user'])
{
$flag=1;
//searching for the user ib the db
echo '<font color="#FF0000">';
echo "* Username is already in use";
echo '</font>';
echo "<br>";
}
else
{
//entering the job seeker data in the user table
$sql="INSERT INTO user (name, Addr, Nation, dob, Gen, cnt, mar, mil, phone, mobile, mail, user)
VALUES
('$fn','$_POST[add]','$_POST[nat]','$dob','$_POST[gg]','$_POST[cnt]','$_POST[Mar]','$_POST[Mil]','$_POST[ph]','$_POST[mo]','$_POST[mail]','$_POST[user]')";
//entering the user and pass in the login table
$sql2="INSERT INTO login (user, pass, type)
VALUES
('$_POST[user]','$_POST[pass]','$_POST[type]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<br>";
if (!mysql_query($sql2,$con))
{
die('Error: ' . mysql_error());
}
echo "<br>";
echo "<br>Thanks for registration $fn ";
exit();
}




Bookmarks