I need to check if the “username” and “afri_mac” exist before a user can register a new account. If the account exists i should be able to echo out “account exists” if the account dose not exist it should then insert the new record
<?php
$servername='localhost';
$usernames='CCC';
$password='XXX';
$dbname = "RRR";
if(isset($_POST['insert']))
{
try {
$afri_first_name = $_POST['afri_first_name'];
$afri_last_name = $_POST['afri_last_name'];
$username = $_POST['username'];
$value = $_POST['value'];
$afri_address = $_POST['afri_address'];
$afri_street = $_POST['afri_street'];
$afri_route = $_POST['afri_route'];
$afri_city = $_POST['afri_city'];
$afri_postal = $_POST['afri_postal'];
$afri_country = $_POST['afri_country'];
$afri_mac = $_POST['afri_mac'];
$afri_ip = $_POST['afri_ip'];
$attribute = $_POST['attribute'];
$op = $_POST['op'];
$afri_note = $_POST['afri_note'];
$afri_phone = $_POST['afri_phone'];
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $usernames, $password);
/* set the PDO error mode to exception */
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO radcheck (afri_first_name,afri_last_name,username,value,afri_address,afri_street,afri_route,afri_city,afri_postal,afri_country,afri_mac,afri_ip,attribute,op,afri_note,afri_phone)
VALUES ('$afri_first_name', '$afri_last_name','$username','$value','$afri_address','$afri_street','$afri_route','$afri_city','$afri_postal','$afri_country','$afri_mac','$afri_ip','$attribute','$op','$afri_note','$afri_phone')";
$conn->exec($sql);
/* echo "<meta http-equiv='refresh' content='0'>"; */
echo "<div class='alert alert-success fade show' align='center'>Registration <strong>Successfully</strong> Completed</div>"; }
catch(PDOException $e)
{
echo "<div class='alert alert-danger fade show' align='center'>Oops... Your registration <strong>failed</strong>. Please try again</div>";
}
$conn = null;
}
?>