SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Undefined method error?

    Hey,

    I have this method

    PHP Code:
    public function addUser($firstname$lastname$username$password$email) {
        
    $this->hDB->prepare("INSERT INTO user VALUES (?, ?, ? ,? ,?)");
        
    $this->hDB->bind_param('sssss'$firstname$lastname$username$password$email);
        
    $this->hDB->execute();
        if (
    $this->hDB->execute()) {
          return 
    true;
        }
        return 
    false;
      } 
    I defined $this->hDB in my constructor
    PHP Code:
    $this->hDB = @new mysqli($strHost$strUsername$strPassword$strDB); 
    I'm getting a fatal error
    Code:
    Fatal error: Call to undefined method mysqli::bind_param() in C:\Users\9three\Desktop\Server\www\class.User.html on line 21
    I tried a couple of different things but it did no good, I still got the same error.

    Can anyone lend a hand? Thanks

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Sure, bind_param is method of mysqli_stmt, not mysqli.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried this

    PHP Code:
    public function addUser($firstname$lastname$username$password$email) {
        
    $stmt $this->hDB->prepare("INSERT INTO user VALUES (?, ?, ? ,? ,?)");
        
    $stmt->bind_param('sssss'$firstname$lastname$username$password$email);
        
    $stmt->execute();
        if (
    $stmt->execute()) {
          return 
    true;
        }
        return 
    false;
      } 
    But it's a no go.

    Edit:

    I just tried

    PHP Code:
    public function addUser($firstname$lastname$username$password$email) {
        
    $stmt $this->hDB->stmt_init();
        
    $stmt->prepare("INSERT INTO user VALUES (?, ?, ? ,? ,?)");
        
    $stmt->bind_param('sssss'$firstname$lastname$username$password$email);
        
    $stmt->execute();
        if (
    $stmt->execute()) {
          return 
    true;
        }
        return 
    false;
      } 
    I'm getting an output of "user not added" (an echo I created if it returned false) and an error of "invalid object or resource mysqli_stmt"

    Edit: 2

    I changed my SQL statement around a little and it worked perfectly. Here's the updates code for anyone who might have this problem.
    PHP Code:
    public function addUser($firstname$lastname$username$password$email) {
        
    $stmt $this->hDB->stmt_init();
        
    $stmt->prepare("INSERT INTO user (firstname, lastname, username, password, email)VALUES (?, ?, ? ,? ,?)");
        
    $stmt->bind_param('sssss'$firstname$lastname$username$password$email);
        
    $stmt->execute();
        if (
    $stmt->execute()) {
          return 
    true;
        }
        return 
    false;
      } 
    Thank you anyway SB.

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Strangely, according to the documentation you should add a terminating semi-colon to the statement or append a '\g'.
    PHP Code:
    public function addUser($firstname$lastname$username$password$email) {
        
    $stmt $this->hDB->stmt_init();
        
    $stmt->prepare("INSERT INTO user VALUES (?, ?, ? ,? ,?);");
        
    $stmt->bind_param('sssss'$firstname$lastname$username$password$email);
        
    $stmt->execute();
        if (
    $stmt->execute()) {
          return 
    true;
        }
        return 
    false;

    Other than that, it looks fine to my untrained eye.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  5. #5
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nooooooo. You read it wrong. It says to NOT add a semi-colon

    Note: You should not add a terminating semicolon or \g to the statement.

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    *whistles*

    Eeep. Next!
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •