I am trying check if username or email already exists . This is my form
<form role="form" action="kys_SignUp.php" method="post">
<div class="form-group">
<label for="email" >Email address:</label>
<input type="email" style="width: 300px" class="form-control" name="email" id="email" required>
</div>
<div class="form-group">
<label for="Username" >Username:</label>
<input type="text" style="width: 300px" class="form-control" name="username" id="Username" required>
</div>
<div class="form-group">
<label for="password" >Password:</label>
<input type="password" style="width: 300px" class="form-control" id="password" name="password" required>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
I am sending the data in Post Method. My server side script looks like this
<?php
include "kys_DbConnect.php";
$email = $username = $password = "";
if($_SERVER["REQUEST_METHOD"] == "POST"){
$email = cleanData($_POST["email"]);
$username = cleanData($_POST["username"]);
$password = cleanData($_POST["password"]);
}
$stmt = $con->prepare("SELECT * FROM kys_users WHERE username=? OR email=?");
$stmt->bind_param("ss",$username,$email);
$stmt->execute();
$stmt->bind_result($id,$email,$username,$password);
$stmt->fetch();
if($username == ""){
header("Location : http://localhost/KeyStroke/index.html ");
exit();
}
else{
echo "Username or Email already exists";
}
function cleanData($data){
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
This is my kys_DbConnect.php
<?php
$serverName = "localhost";
$username = "jois";
$password = "iluvcoding";
$db_name = "kys_userdata";
$con = new mysqli($serverName,$username,$password,$db_name);
if($con->connect_error){
echo "Connection Error";
}
?>
I don't know why but it print's nothing nor redirects to index.html (index.html exists). How can I figure out what's wrong with my code?