I have a problem with inserting informations in mysql database












-1















im actully new to php and mysqli programing, im creating a login and registration form. I did some research on internet about coding and how to get this done and i'm getting problem with inserting information into mysql database, when i'm trying to register a user. I'm getting message " SQLSTATE[HY093]: Invalid parameter number: parameter was not defined "



require_once 'dbconfig.php';

class USER
{
private $conn;

public function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->conn = $db;
}

public function runQuery($sql)
{
$stmt = $this->conn->prepare($sql);
return $stmt;
}

public function lasdID()
{
$stmt = $this->conn->lastInsertId();
return $stmt;
}

public function register($uname,$email,$upass,$code,$spol)
{
try
{
$password = md5($upass);
$stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode,spol)
VALUES(:user_name, :user_mail, :user_pass, :active_code, :spol)");
$stmt->bindparam(":user_mail",$email);
$stmt->bindparam(":user_pass",$password);
$stmt->bindparam(":spol",$spol);
$stmt->bindparam(":active_code",$code);
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}

public function login($email,$upass)
{
try
{
$stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
$stmt->execute(array(":email_id"=>$email));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);

if($stmt->rowCount() == 1)
{
if($userRow['userStatus']=="Y")
{
if($userRow['userPass']==md5($upass))
{
$_SESSION['userSession'] = $userRow['userID'];
return true;
}
else
{
header("Location: index.php?narobe");
exit;
}
}
else
{
header("Location: index.php?inactive");
exit;
}
}
else
{
header("Location: index.php?error");
exit;
}
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
public function is_logged_in()
{
if(isset($_SESSION['userSession']))
{
return true;
}
}
public function redirect($url)
{
header("Location: $url");
}

public function logout()
{
session_destroy();
$_SESSION['userSession'] = false;
}


i'm not sure if i made mistake inside of mysql table or i just typed a wrong code.
If someone could help me to solve a problem than that will be amazing.



Here is image of mysql table



https://ibb.co/djfXDK0










share|improve this question




















  • 1





    Hi. Please check your query: you have 5 placeholders, but you are assigning only 4 with bind param. I guess you are not binding ":user_name".

    – BenRoob
    Jan 19 at 11:45













  • you have 5 parameter but 4 times using bindParam . $stmt->bindparam(":user_name",$name) is missing

    – Ali Ghalambaz
    Jan 19 at 11:46











  • Never store passwords in clear text or using MD5/SHA1! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

    – Dharman
    Jan 19 at 15:11











  • Are you sure that you are ok with user latin1_swedish_ci collation? I would recommend to switch all your tables to utf8mb4_unicode_ci

    – Dharman
    Jan 19 at 15:14











  • @BenRoob yeah i saw that haha, thanks for helping me out :)

    – Fizzy
    Jan 19 at 17:15
















-1















im actully new to php and mysqli programing, im creating a login and registration form. I did some research on internet about coding and how to get this done and i'm getting problem with inserting information into mysql database, when i'm trying to register a user. I'm getting message " SQLSTATE[HY093]: Invalid parameter number: parameter was not defined "



require_once 'dbconfig.php';

class USER
{
private $conn;

public function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->conn = $db;
}

public function runQuery($sql)
{
$stmt = $this->conn->prepare($sql);
return $stmt;
}

public function lasdID()
{
$stmt = $this->conn->lastInsertId();
return $stmt;
}

public function register($uname,$email,$upass,$code,$spol)
{
try
{
$password = md5($upass);
$stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode,spol)
VALUES(:user_name, :user_mail, :user_pass, :active_code, :spol)");
$stmt->bindparam(":user_mail",$email);
$stmt->bindparam(":user_pass",$password);
$stmt->bindparam(":spol",$spol);
$stmt->bindparam(":active_code",$code);
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}

public function login($email,$upass)
{
try
{
$stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
$stmt->execute(array(":email_id"=>$email));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);

if($stmt->rowCount() == 1)
{
if($userRow['userStatus']=="Y")
{
if($userRow['userPass']==md5($upass))
{
$_SESSION['userSession'] = $userRow['userID'];
return true;
}
else
{
header("Location: index.php?narobe");
exit;
}
}
else
{
header("Location: index.php?inactive");
exit;
}
}
else
{
header("Location: index.php?error");
exit;
}
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
public function is_logged_in()
{
if(isset($_SESSION['userSession']))
{
return true;
}
}
public function redirect($url)
{
header("Location: $url");
}

public function logout()
{
session_destroy();
$_SESSION['userSession'] = false;
}


i'm not sure if i made mistake inside of mysql table or i just typed a wrong code.
If someone could help me to solve a problem than that will be amazing.



Here is image of mysql table



https://ibb.co/djfXDK0










share|improve this question




















  • 1





    Hi. Please check your query: you have 5 placeholders, but you are assigning only 4 with bind param. I guess you are not binding ":user_name".

    – BenRoob
    Jan 19 at 11:45













  • you have 5 parameter but 4 times using bindParam . $stmt->bindparam(":user_name",$name) is missing

    – Ali Ghalambaz
    Jan 19 at 11:46











  • Never store passwords in clear text or using MD5/SHA1! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

    – Dharman
    Jan 19 at 15:11











  • Are you sure that you are ok with user latin1_swedish_ci collation? I would recommend to switch all your tables to utf8mb4_unicode_ci

    – Dharman
    Jan 19 at 15:14











  • @BenRoob yeah i saw that haha, thanks for helping me out :)

    – Fizzy
    Jan 19 at 17:15














-1












-1








-1








im actully new to php and mysqli programing, im creating a login and registration form. I did some research on internet about coding and how to get this done and i'm getting problem with inserting information into mysql database, when i'm trying to register a user. I'm getting message " SQLSTATE[HY093]: Invalid parameter number: parameter was not defined "



require_once 'dbconfig.php';

class USER
{
private $conn;

public function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->conn = $db;
}

public function runQuery($sql)
{
$stmt = $this->conn->prepare($sql);
return $stmt;
}

public function lasdID()
{
$stmt = $this->conn->lastInsertId();
return $stmt;
}

public function register($uname,$email,$upass,$code,$spol)
{
try
{
$password = md5($upass);
$stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode,spol)
VALUES(:user_name, :user_mail, :user_pass, :active_code, :spol)");
$stmt->bindparam(":user_mail",$email);
$stmt->bindparam(":user_pass",$password);
$stmt->bindparam(":spol",$spol);
$stmt->bindparam(":active_code",$code);
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}

public function login($email,$upass)
{
try
{
$stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
$stmt->execute(array(":email_id"=>$email));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);

if($stmt->rowCount() == 1)
{
if($userRow['userStatus']=="Y")
{
if($userRow['userPass']==md5($upass))
{
$_SESSION['userSession'] = $userRow['userID'];
return true;
}
else
{
header("Location: index.php?narobe");
exit;
}
}
else
{
header("Location: index.php?inactive");
exit;
}
}
else
{
header("Location: index.php?error");
exit;
}
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
public function is_logged_in()
{
if(isset($_SESSION['userSession']))
{
return true;
}
}
public function redirect($url)
{
header("Location: $url");
}

public function logout()
{
session_destroy();
$_SESSION['userSession'] = false;
}


i'm not sure if i made mistake inside of mysql table or i just typed a wrong code.
If someone could help me to solve a problem than that will be amazing.



Here is image of mysql table



https://ibb.co/djfXDK0










share|improve this question
















im actully new to php and mysqli programing, im creating a login and registration form. I did some research on internet about coding and how to get this done and i'm getting problem with inserting information into mysql database, when i'm trying to register a user. I'm getting message " SQLSTATE[HY093]: Invalid parameter number: parameter was not defined "



require_once 'dbconfig.php';

class USER
{
private $conn;

public function __construct()
{
$database = new Database();
$db = $database->dbConnection();
$this->conn = $db;
}

public function runQuery($sql)
{
$stmt = $this->conn->prepare($sql);
return $stmt;
}

public function lasdID()
{
$stmt = $this->conn->lastInsertId();
return $stmt;
}

public function register($uname,$email,$upass,$code,$spol)
{
try
{
$password = md5($upass);
$stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode,spol)
VALUES(:user_name, :user_mail, :user_pass, :active_code, :spol)");
$stmt->bindparam(":user_mail",$email);
$stmt->bindparam(":user_pass",$password);
$stmt->bindparam(":spol",$spol);
$stmt->bindparam(":active_code",$code);
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}

public function login($email,$upass)
{
try
{
$stmt = $this->conn->prepare("SELECT * FROM tbl_users WHERE userEmail=:email_id");
$stmt->execute(array(":email_id"=>$email));
$userRow=$stmt->fetch(PDO::FETCH_ASSOC);

if($stmt->rowCount() == 1)
{
if($userRow['userStatus']=="Y")
{
if($userRow['userPass']==md5($upass))
{
$_SESSION['userSession'] = $userRow['userID'];
return true;
}
else
{
header("Location: index.php?narobe");
exit;
}
}
else
{
header("Location: index.php?inactive");
exit;
}
}
else
{
header("Location: index.php?error");
exit;
}
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
public function is_logged_in()
{
if(isset($_SESSION['userSession']))
{
return true;
}
}
public function redirect($url)
{
header("Location: $url");
}

public function logout()
{
session_destroy();
$_SESSION['userSession'] = false;
}


i'm not sure if i made mistake inside of mysql table or i just typed a wrong code.
If someone could help me to solve a problem than that will be amazing.



Here is image of mysql table



https://ibb.co/djfXDK0







php mysqli






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 11:56









deceze

394k61534691




394k61534691










asked Jan 19 at 11:34









FizzyFizzy

32




32








  • 1





    Hi. Please check your query: you have 5 placeholders, but you are assigning only 4 with bind param. I guess you are not binding ":user_name".

    – BenRoob
    Jan 19 at 11:45













  • you have 5 parameter but 4 times using bindParam . $stmt->bindparam(":user_name",$name) is missing

    – Ali Ghalambaz
    Jan 19 at 11:46











  • Never store passwords in clear text or using MD5/SHA1! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

    – Dharman
    Jan 19 at 15:11











  • Are you sure that you are ok with user latin1_swedish_ci collation? I would recommend to switch all your tables to utf8mb4_unicode_ci

    – Dharman
    Jan 19 at 15:14











  • @BenRoob yeah i saw that haha, thanks for helping me out :)

    – Fizzy
    Jan 19 at 17:15














  • 1





    Hi. Please check your query: you have 5 placeholders, but you are assigning only 4 with bind param. I guess you are not binding ":user_name".

    – BenRoob
    Jan 19 at 11:45













  • you have 5 parameter but 4 times using bindParam . $stmt->bindparam(":user_name",$name) is missing

    – Ali Ghalambaz
    Jan 19 at 11:46











  • Never store passwords in clear text or using MD5/SHA1! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

    – Dharman
    Jan 19 at 15:11











  • Are you sure that you are ok with user latin1_swedish_ci collation? I would recommend to switch all your tables to utf8mb4_unicode_ci

    – Dharman
    Jan 19 at 15:14











  • @BenRoob yeah i saw that haha, thanks for helping me out :)

    – Fizzy
    Jan 19 at 17:15








1




1





Hi. Please check your query: you have 5 placeholders, but you are assigning only 4 with bind param. I guess you are not binding ":user_name".

– BenRoob
Jan 19 at 11:45







Hi. Please check your query: you have 5 placeholders, but you are assigning only 4 with bind param. I guess you are not binding ":user_name".

– BenRoob
Jan 19 at 11:45















you have 5 parameter but 4 times using bindParam . $stmt->bindparam(":user_name",$name) is missing

– Ali Ghalambaz
Jan 19 at 11:46





you have 5 parameter but 4 times using bindParam . $stmt->bindparam(":user_name",$name) is missing

– Ali Ghalambaz
Jan 19 at 11:46













Never store passwords in clear text or using MD5/SHA1! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

– Dharman
Jan 19 at 15:11





Never store passwords in clear text or using MD5/SHA1! Only store password hashes. Use PHP's password_hash() and password_verify() . If you're running a PHP version lower than 5.5 (which I really hope you aren't), you can use the password_compat library to get the same functionality.

– Dharman
Jan 19 at 15:11













Are you sure that you are ok with user latin1_swedish_ci collation? I would recommend to switch all your tables to utf8mb4_unicode_ci

– Dharman
Jan 19 at 15:14





Are you sure that you are ok with user latin1_swedish_ci collation? I would recommend to switch all your tables to utf8mb4_unicode_ci

– Dharman
Jan 19 at 15:14













@BenRoob yeah i saw that haha, thanks for helping me out :)

– Fizzy
Jan 19 at 17:15





@BenRoob yeah i saw that haha, thanks for helping me out :)

– Fizzy
Jan 19 at 17:15












1 Answer
1






active

oldest

votes


















1














You need to add the $uname parameter to your binding parameters, you forgot a line of code:



    $password = md5($upass);
$stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode,spol)
VALUES(:user_name, :user_mail, :user_pass, :active_code, :spol)");
$stmt->bindparam(":user_name",$uname);
$stmt->bindparam(":user_mail",$email);
$stmt->bindparam(":user_pass",$password);
$stmt->bindparam(":spol",$spol);
$stmt->bindparam(":active_code",$code);
$stmt->execute();


You shouldn´t use MD5 as hash for the password, you should use the php built in functions password_hash() and password_verify()






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54266647%2fi-have-a-problem-with-inserting-informations-in-mysql-database%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You need to add the $uname parameter to your binding parameters, you forgot a line of code:



        $password = md5($upass);
    $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode,spol)
    VALUES(:user_name, :user_mail, :user_pass, :active_code, :spol)");
    $stmt->bindparam(":user_name",$uname);
    $stmt->bindparam(":user_mail",$email);
    $stmt->bindparam(":user_pass",$password);
    $stmt->bindparam(":spol",$spol);
    $stmt->bindparam(":active_code",$code);
    $stmt->execute();


    You shouldn´t use MD5 as hash for the password, you should use the php built in functions password_hash() and password_verify()






    share|improve this answer




























      1














      You need to add the $uname parameter to your binding parameters, you forgot a line of code:



          $password = md5($upass);
      $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode,spol)
      VALUES(:user_name, :user_mail, :user_pass, :active_code, :spol)");
      $stmt->bindparam(":user_name",$uname);
      $stmt->bindparam(":user_mail",$email);
      $stmt->bindparam(":user_pass",$password);
      $stmt->bindparam(":spol",$spol);
      $stmt->bindparam(":active_code",$code);
      $stmt->execute();


      You shouldn´t use MD5 as hash for the password, you should use the php built in functions password_hash() and password_verify()






      share|improve this answer


























        1












        1








        1







        You need to add the $uname parameter to your binding parameters, you forgot a line of code:



            $password = md5($upass);
        $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode,spol)
        VALUES(:user_name, :user_mail, :user_pass, :active_code, :spol)");
        $stmt->bindparam(":user_name",$uname);
        $stmt->bindparam(":user_mail",$email);
        $stmt->bindparam(":user_pass",$password);
        $stmt->bindparam(":spol",$spol);
        $stmt->bindparam(":active_code",$code);
        $stmt->execute();


        You shouldn´t use MD5 as hash for the password, you should use the php built in functions password_hash() and password_verify()






        share|improve this answer













        You need to add the $uname parameter to your binding parameters, you forgot a line of code:



            $password = md5($upass);
        $stmt = $this->conn->prepare("INSERT INTO tbl_users(userName,userEmail,userPass,tokenCode,spol)
        VALUES(:user_name, :user_mail, :user_pass, :active_code, :spol)");
        $stmt->bindparam(":user_name",$uname);
        $stmt->bindparam(":user_mail",$email);
        $stmt->bindparam(":user_pass",$password);
        $stmt->bindparam(":spol",$spol);
        $stmt->bindparam(":active_code",$code);
        $stmt->execute();


        You shouldn´t use MD5 as hash for the password, you should use the php built in functions password_hash() and password_verify()







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 19 at 11:48









        nachonacho

        2,79811223




        2,79811223






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54266647%2fi-have-a-problem-with-inserting-informations-in-mysql-database%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Callistus III

            Ostreoida

            Index Sanctorum