0

The bind_param that is failing is this

$stmt->bind_param('ssss', $this->template->forms->reg_username, $this->template->forms->reg_password, $this->template->forms->reg_email, "Test");

the prepared statement is

$stmt = $this->mysqli->prepare("INSERT INTO 'users' (username, password, email, referr) VALUES (?, ?, ?, ?)");

The whole Register function is

public function Register() {

    unset($this->template->forms->error);
    $this->template->forms->setData();

    if(isset($this->template->forms->submit)) {

        if(!isset($this->template->forms->reg_username)) {
            $this->template->forms->error = "You must enter an username";
        }

        if(!isset($this->template->forms->reg_password)) {
            $this->template->forms->error = "You must enter a password";
        }

        if(!isset($this->template->forms->reg_password_confirm)) {
            $this->template->forms->error = "You must confirm your password";
        }

        if(!isset($this->template->forms->reg_email)) {
            $this->template->forms->error = "You must enter an email address";
        }

        if($this->template->forms->reg_password != $this->template->forms->reg_password_confirm) {
            $this->template->forms->error = "Your passwords must match";
        } else if(strlen($this->template->forms->reg_password) <= 5) {
            $this->template->forms->error = "Your password must be 6 characters or more.";
        }

        if(!$this->template->forms->error) {
            $stmt = $this->mysqli->prepare("INSERT INTO 'users' (username, password, email, referr) VALUES (?, ?, ?, ?)");
            $stmt->bind_param('ssss', $this->template->forms->reg_username, $this->template->forms->reg_password, $this->template->forms->reg_email, "Adam");
            $stmt->execute();
        }

    }
}
D0omz
  • 11
  • It is being loaded through __construct Example function __construct($mysqli, $template) { $this->mysqli = $mysqli; $this->template = $template; } and my global file contains $user = new Users($mysqli, $template); where the $mysqli object is created. – D0omz Dec 28 '13 at 11:02
  • Please note similar questions at the right side of this page. According to site rules you are supposed to use search before asking a new question. – Your Common Sense Dec 28 '13 at 11:07

2 Answers2

1

You have an error in your MySQL query. If the prepared statement couldn't be created the prepare() method will returns false. From the documentation of the prepare() method:

Return Values

mysqli_prepare() returns a statement object or FALSE if an error occurred.

The error message will be stored in the error field of your MySQLi connection object. Always add an error handling when you try to send a query or create a prepared statement.

Progman
  • 16,827
  • 6
  • 33
  • 48
0

I believe you have an error in your SQL which @Progman pointed out in his answer. I believe the mistake is you have 'users' when it is supposed to be `users` which could cause it to fail. Change your SQL to what I have below and let me know if it works.

INSERT INTO `users` (username, password, email, referr) VALUES (?, ?, ?, ?)
g4ost
  • 100
  • 8