Buggy registration system

Posted on 16th Feb 2014 by admin

Hey, I just started scripting in PHP, and I ran into a few problems.
Code: <?php
include('config.php');
if (isset($_POST['set'])){
$user=mysql_real_escape_string($_POST['user']);
$pass=mysql_real_escape_string(md5($_POST['pass']));
if ($user="" or $pass=""){
echo 'Invalid Username/Password';
}
else{
mysql_select_db("db_mycountdown",$db_connect);
$sql=mysql_query("SELECT * FROM users WHERE username='$user'",$db_connect);
$fetch = mysql_num_rows($sql);
if ($fetch>0){
unset($user);
echo 'Error: This user already exists!
';
}
else{
mysql_select_db("db_mycountdown",$db_connect);
$sql = mysql_query("INSERT INTO users (username, password)
VALUES ('$user','$pass')",$db_connect);
echo 'Account Successfully Created!';
}
}
}

echo '<a href="Index.php">Already have an account? Log in!</a>
<form action="" method="post">
Username:<br/>
<input type="text" name="user"/><br />
Password:<br/>
<input type="password" name="pass"/><br />
Confirm Password:<br/>
<input type="password" name="passconfirm"/><br /><br />

<input type="submit" name="set" value="Register" /> <br />
</form>';
?>
my php code here seems really buggy. Can anyone point out any errors? Thanks

Other forums