Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
<?php
session_start();
$servername = "localhost";
$server_username = "root";
$server_password = "";
$dbName = "ar";
try{
$conn = new PDO('mysql:host=localhost;dbname=ar;','root','');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$username = ($_POST['username']);
$password = ($_POST['pw']);
$name = ($_POST['name']);
$cardID = ($_POST['cardID']);
//strength of encryption
$options = [
'cost' => 12,
];
$passwordNew = password_hash($password, PASSWORD_BCRYPT,$options);
// check if the username does not exist in database
$stmt = $conn->prepare('SELECT * FROM accounts WHERE username = :username');
$stmt->bindParam(':username',$username);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// If does not exist - create it (account)
if(!$row){
if($stmt = $conn->prepare('INSERT INTO accounts (username, pw, name, cardID) VALUES (:username, :pw, :name, :cardID)')){
$stmt->bindValue(':username',$username, PDO::PARAM_STR);
$stmt->bindValue(':pw',$passwordNew, PDO::PARAM_STR);
$stmt->bindValue(':name',$name, PDO::PARAM_STR);
$stmt->bindValue(':cardID',$cardID, PDO::PARAM_INT);
$stmt->execute();
echo "0";
}
}
else{
// tells unity if the account exists
die('Account Exists!');
//echo"00";
}
} catch(PDOException $pe){
die("Could not connect" . $pe->getMessage());
}
?>