简体   繁体   中英

Invalid parameter number: parameter was not defined Explination

Im using a simple test form to try and debug this error.

Im trying to write a script where users can update their user information, I have searched SO but have not found anything concrete to help me.

My test code is as follows:

HTML

<form name="info" method="post" enctype="multipart/form-data">
    <input type="text" name="username" id="username">
    <input type="submit" name="submitBtn">
</form>

PHP

        if(isset($_POST['submitBtn'])){
       //Display Errors
      {{ PDO::ATTR_ERRMODE; }}
        $db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );

        $uname =  $_POST['username']; //this displays correct after submit
        $userID = $_SESSION['userID']//this prints correctly when user logged in, which he is
        $sql="UPDATE USERS SET username =:name
              WHERE userID =:uID";
        $stmnt= $db->prepare($sql);

        $stmnt->bindValue('name', $uname);
        $stmnt->bindValue('userID', $userID);
        $result = $stmnt->execute();
        if($result){
            ?>
        <h2>SUCCESS</h2>
    <?php
        }//end result
        else{
            ?>
        <h2>FAIL</h2>
    <?php
        }//else
    }//isset

ERROR MESSAGE

PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

missing : (colon)

   $stmnt->bindValue(':name', $uname);
   $stmnt->bindValue(':userID', $userID);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM