I'm developing an app in php and ms sql. There's this page in the app, which has only one usser input field that takes the username of the user. Not I want to add a feature that checks if the user exists in the database then it directs him to the next page else gives an error.
<?php
require_once './pages/header.php';
require_once './functions/queries.php';
?>
<div class="container" >
<form class="cmxform" id="Form">
<div id="FormResult" class="hide" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<div id="resultFormContent"></div>
</div>
<div class="form-group col-md-12">
* Indicates required field
</div>
<div class="form-row">
<div class="form-group col-md-4">
<label for="fName">First Name *</label>
<input type="text" class="form-control" id="User" name="User" required>
</div>
</div>
<div class="form-group col-md-12">
<button class="btn btn-info btn-primary" id="registerSubmit" type="submit">Submit</button>
</div>
</form>
</div>
queries.php
<?php
require_once("db-connect.php");
class Queries{
public static function getUser($Id){
$conn = DB::databaseConnection();
$sql = "SELECT User FROM Admins WHERE Id = :Id";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':Id', $Id);
if ($stmt->execute()) {
return $stmt->fetch(PDO::FETCH_ASSOC);
} else {
return null;
}
}
}
The page which I want to direct the user to if he exists in the database is "read.php".