php finding an existing data from mysql [duplicate]
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
This question already has an answer here:
Check if username exists in mysql table via php? [duplicate]
3 answers
I am trying to create a registration page and throw an error when the username or the email exists but it doesn't catch the error.
The table name in the database is 'users', username is 'uname' and email is 'email'.
It inserts the data without a problem.
I am using the same array to catch if any field is empty, also they are working perfectly fine.
$query_usr = mysql_query("SELECT * FROM users WHERE uname='$uname' OR email='$email'");
if ($query_usr["uname"] === $uname) {
array_push($errors, "Username already exists");
}
if ($query_usr["email"] === $email) {
array_push($errors, "email already exists");
}
if (count($err) == 0) {
$pass = md5($pass1);
$query = "INSERT INTO users (uname, email, password) VALUES('$uname', '$email', '$pass')";
mysqli_query($connection, $query);
$_SESSION["uname"] = $uname;
$_SESSION["success"] = "You are now logged in";
//header('location: index.php');
}
else{
foreach ($err as $er){
echo $er;
echo "<p> </p>";
}
}
php mysql
marked as duplicate by Masivuye Cokile, RiggsFolly
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 23 '18 at 13:44
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 |
This question already has an answer here:
Check if username exists in mysql table via php? [duplicate]
3 answers
I am trying to create a registration page and throw an error when the username or the email exists but it doesn't catch the error.
The table name in the database is 'users', username is 'uname' and email is 'email'.
It inserts the data without a problem.
I am using the same array to catch if any field is empty, also they are working perfectly fine.
$query_usr = mysql_query("SELECT * FROM users WHERE uname='$uname' OR email='$email'");
if ($query_usr["uname"] === $uname) {
array_push($errors, "Username already exists");
}
if ($query_usr["email"] === $email) {
array_push($errors, "email already exists");
}
if (count($err) == 0) {
$pass = md5($pass1);
$query = "INSERT INTO users (uname, email, password) VALUES('$uname', '$email', '$pass')";
mysqli_query($connection, $query);
$_SESSION["uname"] = $uname;
$_SESSION["success"] = "You are now logged in";
//header('location: index.php');
}
else{
foreach ($err as $er){
echo $er;
echo "<p> </p>";
}
}
php mysql
marked as duplicate by Masivuye Cokile, RiggsFolly
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 23 '18 at 13:44
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.
1
How do you retrieve $uname and $email. PS you're open to SQL injection. PPS check a typo : $err is maybe $errors
– Sfili_81
Nov 23 '18 at 13:40
Every time you use themysql_database extension in new code this happens it is deprecated and has been for years and is gone for ever in PHP7.0+. If you are just learning PHP, spend your energies learning thePDOormysqlidatabase extensions and prepared statements. Start here
– RiggsFolly
Nov 23 '18 at 13:41
mysql_*functions aredepreciated you should usemysqli_*` or pdo with prepared statements... u need to select userid where email or username = supplied then return results if you have results then it exists
– Masivuye Cokile
Nov 23 '18 at 13:41
2
Please dont roll your own password hashing, specially not using MD5() or SHA1(). PHP providespassword_hash()andpassword_verify()please use them. And here are some good ideas about passwords If you are using a PHP version prior to 5.5 there is a compatibility pack available here
– RiggsFolly
Nov 23 '18 at 13:42
add a comment |
This question already has an answer here:
Check if username exists in mysql table via php? [duplicate]
3 answers
I am trying to create a registration page and throw an error when the username or the email exists but it doesn't catch the error.
The table name in the database is 'users', username is 'uname' and email is 'email'.
It inserts the data without a problem.
I am using the same array to catch if any field is empty, also they are working perfectly fine.
$query_usr = mysql_query("SELECT * FROM users WHERE uname='$uname' OR email='$email'");
if ($query_usr["uname"] === $uname) {
array_push($errors, "Username already exists");
}
if ($query_usr["email"] === $email) {
array_push($errors, "email already exists");
}
if (count($err) == 0) {
$pass = md5($pass1);
$query = "INSERT INTO users (uname, email, password) VALUES('$uname', '$email', '$pass')";
mysqli_query($connection, $query);
$_SESSION["uname"] = $uname;
$_SESSION["success"] = "You are now logged in";
//header('location: index.php');
}
else{
foreach ($err as $er){
echo $er;
echo "<p> </p>";
}
}
php mysql
This question already has an answer here:
Check if username exists in mysql table via php? [duplicate]
3 answers
I am trying to create a registration page and throw an error when the username or the email exists but it doesn't catch the error.
The table name in the database is 'users', username is 'uname' and email is 'email'.
It inserts the data without a problem.
I am using the same array to catch if any field is empty, also they are working perfectly fine.
$query_usr = mysql_query("SELECT * FROM users WHERE uname='$uname' OR email='$email'");
if ($query_usr["uname"] === $uname) {
array_push($errors, "Username already exists");
}
if ($query_usr["email"] === $email) {
array_push($errors, "email already exists");
}
if (count($err) == 0) {
$pass = md5($pass1);
$query = "INSERT INTO users (uname, email, password) VALUES('$uname', '$email', '$pass')";
mysqli_query($connection, $query);
$_SESSION["uname"] = $uname;
$_SESSION["success"] = "You are now logged in";
//header('location: index.php');
}
else{
foreach ($err as $er){
echo $er;
echo "<p> </p>";
}
}
This question already has an answer here:
Check if username exists in mysql table via php? [duplicate]
3 answers
php mysql
php mysql
asked Nov 23 '18 at 13:37
aioxieaioxie
11
11
marked as duplicate by Masivuye Cokile, RiggsFolly
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 23 '18 at 13:44
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 Masivuye Cokile, RiggsFolly
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 23 '18 at 13:44
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.
1
How do you retrieve $uname and $email. PS you're open to SQL injection. PPS check a typo : $err is maybe $errors
– Sfili_81
Nov 23 '18 at 13:40
Every time you use themysql_database extension in new code this happens it is deprecated and has been for years and is gone for ever in PHP7.0+. If you are just learning PHP, spend your energies learning thePDOormysqlidatabase extensions and prepared statements. Start here
– RiggsFolly
Nov 23 '18 at 13:41
mysql_*functions aredepreciated you should usemysqli_*` or pdo with prepared statements... u need to select userid where email or username = supplied then return results if you have results then it exists
– Masivuye Cokile
Nov 23 '18 at 13:41
2
Please dont roll your own password hashing, specially not using MD5() or SHA1(). PHP providespassword_hash()andpassword_verify()please use them. And here are some good ideas about passwords If you are using a PHP version prior to 5.5 there is a compatibility pack available here
– RiggsFolly
Nov 23 '18 at 13:42
add a comment |
1
How do you retrieve $uname and $email. PS you're open to SQL injection. PPS check a typo : $err is maybe $errors
– Sfili_81
Nov 23 '18 at 13:40
Every time you use themysql_database extension in new code this happens it is deprecated and has been for years and is gone for ever in PHP7.0+. If you are just learning PHP, spend your energies learning thePDOormysqlidatabase extensions and prepared statements. Start here
– RiggsFolly
Nov 23 '18 at 13:41
mysql_*functions aredepreciated you should usemysqli_*` or pdo with prepared statements... u need to select userid where email or username = supplied then return results if you have results then it exists
– Masivuye Cokile
Nov 23 '18 at 13:41
2
Please dont roll your own password hashing, specially not using MD5() or SHA1(). PHP providespassword_hash()andpassword_verify()please use them. And here are some good ideas about passwords If you are using a PHP version prior to 5.5 there is a compatibility pack available here
– RiggsFolly
Nov 23 '18 at 13:42
1
1
How do you retrieve $uname and $email. PS you're open to SQL injection. PPS check a typo : $err is maybe $errors
– Sfili_81
Nov 23 '18 at 13:40
How do you retrieve $uname and $email. PS you're open to SQL injection. PPS check a typo : $err is maybe $errors
– Sfili_81
Nov 23 '18 at 13:40
Every time you use the
mysql_ database extension in new code this happens it is deprecated and has been for years and is gone for ever in PHP7.0+. If you are just learning PHP, spend your energies learning the PDO or mysqli database extensions and prepared statements. Start here– RiggsFolly
Nov 23 '18 at 13:41
Every time you use the
mysql_ database extension in new code this happens it is deprecated and has been for years and is gone for ever in PHP7.0+. If you are just learning PHP, spend your energies learning the PDO or mysqli database extensions and prepared statements. Start here– RiggsFolly
Nov 23 '18 at 13:41
mysql_* functions are depreciated you should use mysqli_*` or pdo with prepared statements... u need to select userid where email or username = supplied then return results if you have results then it exists– Masivuye Cokile
Nov 23 '18 at 13:41
mysql_* functions are depreciated you should use mysqli_*` or pdo with prepared statements... u need to select userid where email or username = supplied then return results if you have results then it exists– Masivuye Cokile
Nov 23 '18 at 13:41
2
2
Please dont roll your own password hashing, specially not using MD5() or SHA1(). PHP provides
password_hash() and password_verify() please use them. And here are some good ideas about passwords If you are using a PHP version prior to 5.5 there is a compatibility pack available here– RiggsFolly
Nov 23 '18 at 13:42
Please dont roll your own password hashing, specially not using MD5() or SHA1(). PHP provides
password_hash() and password_verify() please use them. And here are some good ideas about passwords If you are using a PHP version prior to 5.5 there is a compatibility pack available here– RiggsFolly
Nov 23 '18 at 13:42
add a comment |
1 Answer
1
active
oldest
votes
Change From
if (count($err) == 0) {
To
if (count($errors) == 0) {
Also change following code like this in else part
foreach ($errors as $er){
echo $er;
echo "<p> </p>";
}
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Change From
if (count($err) == 0) {
To
if (count($errors) == 0) {
Also change following code like this in else part
foreach ($errors as $er){
echo $er;
echo "<p> </p>";
}
add a comment |
Change From
if (count($err) == 0) {
To
if (count($errors) == 0) {
Also change following code like this in else part
foreach ($errors as $er){
echo $er;
echo "<p> </p>";
}
add a comment |
Change From
if (count($err) == 0) {
To
if (count($errors) == 0) {
Also change following code like this in else part
foreach ($errors as $er){
echo $er;
echo "<p> </p>";
}
Change From
if (count($err) == 0) {
To
if (count($errors) == 0) {
Also change following code like this in else part
foreach ($errors as $er){
echo $er;
echo "<p> </p>";
}
answered Nov 23 '18 at 13:40
SadikhasanSadikhasan
14.2k136095
14.2k136095
add a comment |
add a comment |
1
How do you retrieve $uname and $email. PS you're open to SQL injection. PPS check a typo : $err is maybe $errors
– Sfili_81
Nov 23 '18 at 13:40
Every time you use the
mysql_database extension in new code this happens it is deprecated and has been for years and is gone for ever in PHP7.0+. If you are just learning PHP, spend your energies learning thePDOormysqlidatabase extensions and prepared statements. Start here– RiggsFolly
Nov 23 '18 at 13:41
mysql_*functions aredepreciated you should usemysqli_*` or pdo with prepared statements... u need to select userid where email or username = supplied then return results if you have results then it exists– Masivuye Cokile
Nov 23 '18 at 13:41
2
Please dont roll your own password hashing, specially not using MD5() or SHA1(). PHP provides
password_hash()andpassword_verify()please use them. And here are some good ideas about passwords If you are using a PHP version prior to 5.5 there is a compatibility pack available here– RiggsFolly
Nov 23 '18 at 13:42