Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $conn = new mysqli('localhost', 'root', '', 'user');
- if (mysqli_connect_errno()) {
- printf("Connect failed: %sn", mysqli_connect_error());
- exit();}
- $uname = $_POST['uname'];
- $psw = $_POST['psw'];
- $options = [
- 'cost' => 12,];
- $hashedpassword= password_hash($psw, PASSWORD_BCRYPT, $options);
- $result = $mysqli->query("SELECT username FROM registration WHERE username = '$uname'");
- $row_count = $result->num_rows; if($row_count == 1) {
- echo 'User already exists, try another one.'; }
- else {
- $query = "INSERT INTO user (username, password) VALUES(?, ?)";
- $statement = $mysqli->prepare($query);
- $statement->bind_param('ss', $uname, $hashedpassword);
- if($statement->execute())
- {
- print 'Success! Last inserted record : ' .$statement->insert_id .'<br />';
- }
- else
- {
- die('Error : ('. $mysqli->errno .') '. $mysqli->error);
- }
- $statement->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement