0% found this document useful (0 votes)
17 views

Dbfunctions

mm
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Dbfunctions

mm
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

<?

php
include("db.php");
include("functions.php");

if($_SERVER['REQUEST_METHOD'] == "POST")
{
//something was posted
$username = $_POST['username'];
$password = $_POST['password'];
$password_conf = $_POST['password_conf'];
// CHECK IF CONFIRMED PASSWORD IS THE SAME AS PASSWORD
if ($password == $password_conf) {
// CHECK IF INPUT IS NOT EMPTY AND USERNAME IS NOT NUMERIC
if(!empty($username) && !empty($password) && !is_numeric($username))
{
// $var = "SELECT count(*) FROM admin";
// $query = $con2-> query($var);

// CHECK IF USERNAME IS ALREADY TAKEN


$queryString = "SELECT count(*) as countusers FROM admin WHERE username =
'$username'";
$result = mysqli_query($con, $queryString);
while($row = mysqli_fetch_assoc($result))
{
//
if($row["countusers"] != 0)
{
$_SESSION['userexists'] = "Username Already Exists!";
header("location: register.php");
exit;
}
else {// ACTUAL PROCESS IF USER ARE NOT REGISTERED
$user_id = rand();

$password = password_hash($password, PASSWORD_DEFAULT);


$sql = "INSERT INTO admin (userid, username, password) VALUES ( '$user_id',
'$username', '$password')";
if (mysqli_query($con, $sql)) {
$_SESSION['regsuccess'] = "Admin Added!";
header("location: login.php");
exit;
}
else {
echo "Error: " . $sql . "<br>" . mysqli_error($con);
}
}
}

You might also like