Calling mysql from PDO returns error unknown field?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • samvb
    New Member
    • Oct 2006
    • 228

    Calling mysql from PDO returns error unknown field?

    I been staring and editing the codes for hours...I cant seem to understand it at all. I want to login basically. I have a mysql stored procedure in this way:

    Code:
    CREATE DEFINER=`dan78`@`localhost` PROCEDURE `spLogMeIn`(IN uname varchar(12), IN upwd varchar(40))
    BEGIN
    SELECT memberid,memstatus,mememail,avatarname FROM tblmembers WHERE memuname=uname AND mempwd=upwd;
    END
    PHP: db.php

    Code:
      public function runSelectQuery($sql) {
           try {
            $q = $this->conn->prepare($sql);
            $q->execute();
            return $row = $q->fetchAll();
    		}
    		catch (PDOException $e){
    		return $e->getCode();
    		}
        }
    and now the login.php

    Code:
    require(DBFILE);
    
    $mydb = new dbACW();
    $result = $mydb->runSelectQuery("CALL spLogMeIn($uname,$upwd);");
    The error code it returns is Unknown field name $username i.e. if i enter samsam for username it would be Unknown fieldname samsam in the fieldlist.

    I have other stored procedures that are similar and work awesome. What am i doing wrong?
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    quoot: "The error code it returns is Unknown field name $username"

    In your code there is no $username..... ?

    Comment

    • samvb
      New Member
      • Oct 2006
      • 228

      #3
      dude...$usernam e is just a placeholder. wat ever is in it (e.g if i entere sam as username), error would be "unknown field sam in field list)

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        dude...$usernam e is just a placeholder.
        that’s your intention but to SQL you indeed give it as field name.

        Comment

        • samvb
          New Member
          • Oct 2006
          • 228

          #5
          I think i am not clear...look at the mysql code

          SELECT * FROM TBL WHERE FIELDNAME=param eter;

          i send parameter from php. but it says parameter is unknown field. parameter is a value to compare against the field FIELDNAME..

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            Your stored procedure call doesn't delimit your parameters as strings

            Comment

            • samvb
              New Member
              • Oct 2006
              • 228

              #7
              I actually solved after a while...i still dont know why others work but it doesnt. I just declared a variable to store the sql statement, prepare it then execute it.

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                you prepare it with the values already in the Statement, so it shouldn’t be called a proper prepared statement.

                Comment

                Working...