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;
}







-2
















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>";
}
}









share|improve this question













marked as duplicate by Masivuye Cokile, RiggsFolly mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

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 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






  • 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


















-2
















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>";
}
}









share|improve this question













marked as duplicate by Masivuye Cokile, RiggsFolly mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

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 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






  • 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














-2












-2








-2









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>";
}
}









share|improve this question















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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 13:37









aioxieaioxie

11




11




marked as duplicate by Masivuye Cokile, RiggsFolly mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

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 mysql
Users with the  mysql badge can single-handedly close mysql questions as duplicates and reopen them as needed.

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 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






  • 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














  • 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 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






  • 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








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












1 Answer
1






active

oldest

votes


















0














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>";
}





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    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>";
    }





    share|improve this answer




























      0














      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>";
      }





      share|improve this answer


























        0












        0








        0







        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>";
        }





        share|improve this answer













        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>";
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 13:40









        SadikhasanSadikhasan

        14.2k136095




        14.2k136095

















            這個網誌中的熱門文章

            Academy of Television Arts & Sciences

            L'Équipe

            1995 France bombings