<?php

 

session_start();

 

if( isset($_SESSION['user_id']) ){

    header("Location: /");

}

 

require 'database.php';

 

$message = '';

 

if(!empty($_POST['username']) && !empty($_POST['email']) && !empty($_POST['password'])):

     

    // Enter the new user in the database

         $kullaniciadivarmi = $db->prepare("SELECT * FROM users WHERE username=:d");

$kullaniciadivarmi->execute([":d" => $_POST['username']]);

         $kullaniciadivarmi->rowCount()){

echo "kullanıcı adı kayıtlı";

}else{



 $epostavarmi= $db->prepare("SELECT * FROM users WHERE email=:d");

$epostavarmi ->execute([":d" => $_POST['email']]);

if($epostavarmi->rowCount()){

echo "eposta kayıtlı";

}else{



  $sql = "INSERT INTO users (username,email,password,status) VALUES (:username, :email, :password, 1)";

    $stmt = $conn->prepare($sql);

    $stmt->bindParam(':username', $_POST['username']);

    $stmt->bindParam(':email', $_POST['email']);

    $stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));

    if( $stmt->execute() ):    

        $message = 'Kayıt Başarılı!';

    else:

        $message = 'Kayıt Başarısız Lütfen Bilgilerinizi Kontrol Ediniz!';

    endif;





}



}



  

 

endif;

 

?>