PHP No allow to register same username [duplicate]
up vote
-1
down vote
favorite
This question already has an answer here:
PHP Checking if user exists with PDO
2 answers
Check if username exists PDO
3 answers
What should I do in the code below so that you can not register the same username? Please explain to me or send the code ready. I am new in such things. Sorry for my bad English.
<?php
session_start();
if( isset($_SESSION['user_id']) )
header("Location: /panel/");
$server = '';
$username = '';
$password = '';
$database = '';
try
$conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
catch(PDOException $e)
die( "Connection failed: " . $e->getMessage());
$message = '';
if(!empty($_POST['username']) && !empty($_POST['password'])):
$sql = "INSERT INTO users (username, password) VALUES (:username, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
if( $stmt->execute() ):
$message = '<font color=008000>successfully registered</font>';
else:
$message = '<font color=be3737>Sorry there must have been an issue creating your account</font>';
endif;
endif;
?>php pdo
marked as duplicate by Funk Forty Niner
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 11 at 14:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
-1
down vote
favorite
This question already has an answer here:
PHP Checking if user exists with PDO
2 answers
Check if username exists PDO
3 answers
What should I do in the code below so that you can not register the same username? Please explain to me or send the code ready. I am new in such things. Sorry for my bad English.
<?php
session_start();
if( isset($_SESSION['user_id']) )
header("Location: /panel/");
$server = '';
$username = '';
$password = '';
$database = '';
try
$conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
catch(PDOException $e)
die( "Connection failed: " . $e->getMessage());
$message = '';
if(!empty($_POST['username']) && !empty($_POST['password'])):
$sql = "INSERT INTO users (username, password) VALUES (:username, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
if( $stmt->execute() ):
$message = '<font color=008000>successfully registered</font>';
else:
$message = '<font color=be3737>Sorry there must have been an issue creating your account</font>';
endif;
endif;
?>php pdo
marked as duplicate by Funk Forty Niner
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 11 at 14:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
This question already has an answer here:
PHP Checking if user exists with PDO
2 answers
Check if username exists PDO
3 answers
What should I do in the code below so that you can not register the same username? Please explain to me or send the code ready. I am new in such things. Sorry for my bad English.
<?php
session_start();
if( isset($_SESSION['user_id']) )
header("Location: /panel/");
$server = '';
$username = '';
$password = '';
$database = '';
try
$conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
catch(PDOException $e)
die( "Connection failed: " . $e->getMessage());
$message = '';
if(!empty($_POST['username']) && !empty($_POST['password'])):
$sql = "INSERT INTO users (username, password) VALUES (:username, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
if( $stmt->execute() ):
$message = '<font color=008000>successfully registered</font>';
else:
$message = '<font color=be3737>Sorry there must have been an issue creating your account</font>';
endif;
endif;
?>php pdo
This question already has an answer here:
PHP Checking if user exists with PDO
2 answers
Check if username exists PDO
3 answers
What should I do in the code below so that you can not register the same username? Please explain to me or send the code ready. I am new in such things. Sorry for my bad English.
<?php
session_start();
if( isset($_SESSION['user_id']) )
header("Location: /panel/");
$server = '';
$username = '';
$password = '';
$database = '';
try
$conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
catch(PDOException $e)
die( "Connection failed: " . $e->getMessage());
$message = '';
if(!empty($_POST['username']) && !empty($_POST['password'])):
$sql = "INSERT INTO users (username, password) VALUES (:username, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
if( $stmt->execute() ):
$message = '<font color=008000>successfully registered</font>';
else:
$message = '<font color=be3737>Sorry there must have been an issue creating your account</font>';
endif;
endif;
?>This question already has an answer here:
PHP Checking if user exists with PDO
2 answers
Check if username exists PDO
3 answers
<?php
session_start();
if( isset($_SESSION['user_id']) )
header("Location: /panel/");
$server = '';
$username = '';
$password = '';
$database = '';
try
$conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
catch(PDOException $e)
die( "Connection failed: " . $e->getMessage());
$message = '';
if(!empty($_POST['username']) && !empty($_POST['password'])):
$sql = "INSERT INTO users (username, password) VALUES (:username, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
if( $stmt->execute() ):
$message = '<font color=008000>successfully registered</font>';
else:
$message = '<font color=be3737>Sorry there must have been an issue creating your account</font>';
endif;
endif;
?><?php
session_start();
if( isset($_SESSION['user_id']) )
header("Location: /panel/");
$server = '';
$username = '';
$password = '';
$database = '';
try
$conn = new PDO("mysql:host=$server;dbname=$database;", $username, $password);
catch(PDOException $e)
die( "Connection failed: " . $e->getMessage());
$message = '';
if(!empty($_POST['username']) && !empty($_POST['password'])):
$sql = "INSERT INTO users (username, password) VALUES (:username, :password)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));
if( $stmt->execute() ):
$message = '<font color=008000>successfully registered</font>';
else:
$message = '<font color=be3737>Sorry there must have been an issue creating your account</font>';
endif;
endif;
?>php pdo
php pdo
edited Nov 11 at 14:40
Funk Forty Niner
80.5k124799
80.5k124799
asked Nov 11 at 14:34
Jakub Mikuło
1
1
marked as duplicate by Funk Forty Niner
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 11 at 14:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Funk Forty Niner
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 11 at 14:37
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes