I have created a signup form and it is working perfectly but now the issue is even if the user are not able to register due to common username the PID still increases.
Here is the HTML form:
<form class="form-register" method="post" action="php/reg.php">
<div class="form-register-with-email">
<div class="form-white-background">
<div class="form-title-row">
<h1>Create an account</h1>
</div>
<div class="form-row">
<label>
<span>First Name</span>
<input type="text" name="first_name">
</label>
</div>
<div class="form-row">
<label>
<span>Last Name</span>
<input type="text" name="last_name">
</label>
</div>
<div class="form-row">
<label>
<span>Username</span>
<input type="text" name="username">
</label>
</div>
<div class="form-row">
<label>
<span>Email</span>
<input type="email" name="email">
</label>
</div>
<div class="form-row">
<label>
<span>Password</span>
<input type="password" name="password">
</label>
</div>
<div class="form-row">
<label class="form-checkbox">
<input type="checkbox" name="checkbox" checked>
<span>I agree to the <a href="#">terms and conditions</a></span>
</label>
</div>
<div class="form-row">
<button type="submit" name="submit">Register</button>
</div>
</div>
<a href="form-login.html" class="form-log-in-with-existing">Already have an account? Login here →</a>
</div>
<div class="form-sign-in-with-social">
<div class="form-row form-title-row">
<span class="form-title">Sign in with</span>
</div>
<a href="#" class="form-google-button">Google</a>
<a href="#" class="form-facebook-button">Facebook</a>
<a href="#" class="form-twitter-button">Twitter</a>
</div>
</form>
Here is the php code:
<?php
include('connect.php');
if(isset($_REQUEST['submit'])) {
if($_REQUEST['first_name'] == '' || $_REQUEST['last_name'] == '' || $_REQUEST['username'] == ''|| $_REQUEST['email'] == '' || $_REQUEST['password'] === '' ) {
echo "please fill the empty field.";
}
else {
$sql="SELECT pid FROM players WHERE username = '".$_REQUEST['username']."'";
$res=mysql_query($sql);
if (mysql_num_rows($res) == 0) {
$sql="insert into players(first_name,last_name,username,email,password) values('".$_REQUEST['first_name']."', '".$_REQUEST['last_name']."', '".$_REQUEST['username']."', '".$_REQUEST['email']."', '".$_REQUEST['password']."')";
$res=mysql_query($sql);
} else{
echo "username was already used";
}
if($res) {
echo "Record successfully inserted";
}
else {
echo "There is some problem in inserting record";
}
}
}
?>

