So I've been looking at numerous references for a php registration page, however I'm running into trouble. Upon reload of page, the line "Username already exists" is always there. I know there's a problem with my code, but seeing that I'm not PHP Savvy, I don't really know how to fix it; I've been looking around for a couple hours and can't seem to fix this still, as well as trying many many different ways to register an account. Maybe one of you can help me. Here's my code:
<html>
<body>
<form method="post" action="">
Username: <input type="text" name="username" value="" /><br/>
Password: <input type="password" name="pass" value="" /><br/>
Repeat Password: <input type="password" name="pass2" value=""/><br/>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
<?php
$con = mysql_connect("localhost", "root", "123");
$db = mysql_select_db("cq3");
$Username = isset($_POST['Username']);
$sql = "SELECT * FROM accounts WHERE Username = '$Username'";
$result = mysql_query($sql, $con);
if(mysql_num_rows($result)){
echo "Username already exists!";
}
else
{
if(isset($_POST['submit']))
{
$sql = "INSERT INTO `accounts` (Username, Password) VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
$sql = mysql_query($sql);
}
}
?>