0

So I am working on a project using UserCake. I have added fields to the 'users' table. So far, everything works great. The issue I am having is when you register, it returns successful but the SQL statement did not put any of the form data into the database.

So far, I have been successful at adding the necessary fields and I am able to pull data from those fields however, I am not able to push data to the database. I have a feeling it has to do with the bind_param statement, but I am not sure. Here's what I am dealing with:

EDIT 9/30 5pm >>> Only issue at this point is that the data is not being put into the table.

$stmt = $mysqli->prepare("INSERT INTO ".$db_table_prefix."users (
                password,
                email,
                activation_token,
                last_activation_request,
                lost_password_request,
                active,
                title,
                sign_up_stamp,
                last_sign_in_stamp,
                company,
                address_1,
                address_2,
                city,
                state,
                zip,
                paid,
                first_name,
                last_name
                )
                VALUES (
                ?,
                ?,
                ?,
                '".time()."',
                '0',
                ?,
                'New Member',
                '".time()."',
                '0',
                ?,
                ?,
                ?,
                ?,
                ?,
                ?,
                '0',
                ?,
                ?
                )");

            $stmt->bind_param("sssisssssiiss", $secure_pass, $this->clean_email, $this->activation_token, $this->user_active, $this->company, $this->address_1, $this->address_2, $this->city, $this->state, $this->zip, $this->first_name, $this->last_name);
            $stmt->execute();
            print_r($stmt);
            $inserted_id = $mysqli->insert_id;
            $stmt->close();

EDIT >>> Solved empty array issue

I am calling the new user like this: $user = new User($password, $email, $token, $activationRequest, $passwordRequest, $active, $title, $signUp, $signIn, $company, $address_1, $address_2, $city, $state, $zip, $paid, $first_name, $last_name);

EDIT >>> TABLE uc_users ( id int(11) NOT NULL, password varchar(225) NOT NULL,

email varchar(150) NOT NULL,

activation_token varchar(225) NOT NULL,

last_activation_request int(11) NOT NULL,

lost_password_request tinyint(1) NOT NULL,

active tinyint(1) NOT NULL,

title varchar(150) NOT NULL,

sign_up_stamp int(11) NOT NULL,

last_sign_in_stamp int(11) NOT NULL,

company varchar(50) DEFAULT NULL,

address_1 varchar(50) NOT NULL,

address_2 varchar(50) NOT NULL,

city varchar(50) NOT NULL,

state varchar(20) NOT NULL,

zip int(5) NOT NULL,

paid tinyint(1) NOT NULL,

first_name varchar(50) NOT NULL,

last_name varchar(50) NOT NULL

) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

1 Answers1

0

The field Company on your table not allowing NULL values, but Your'e sending it null as I see in Your question ( print_r($this) section ).

So You have 2 ways to solve this problem,

  1. If you really need for company, set Company field as required and check it during the validation (after sending query), this will keep you away from such problems.
  2. Otherwise alter your company field in database, and allow NULLs for it.
Vahe Shadunts
  • 1,956
  • 14
  • 18
  • I understand that, and it isn't required. However, I am typing in a company name. Even still first_name, last_name, etc. are all empty as well. – CoconuttMonkey Sep 30 '14 at 20:32
  • Can you provide the DDL of your table please? – Vahe Shadunts Sep 30 '14 at 20:33
  • I'm not 100% positive what you mean by DDL, but I'm using MySQL.. Is this what you're looking for? – CoconuttMonkey Sep 30 '14 at 20:40
  • I know, I mean the create table query of users table – Vahe Shadunts Sep 30 '14 at 20:43
  • Okay that's what I was thinking. I just put it up there – CoconuttMonkey Sep 30 '14 at 20:44
  • this is paradox for me, the exception you've wrote is `[error] => Column 'company' cannot be null )` but the company field accepts nulls in table.. can you try run one more time and see the error, is that same ?? – Vahe Shadunts Sep 30 '14 at 20:53
  • Okay so I got a little further. In the __construct funtion, I need to do this with each variable: `$this->first_name = $first_name;` So now, when I `print_r($user)` the array is full. However, it is still not putting the data into the database. – CoconuttMonkey Sep 30 '14 at 20:56
  • I just checked, Had to change the `?,` for paid to `'0',` and I fixed `bind_param()` to match. I am now getting this error: `mysqli_stmt Object ( [affected_rows] => 0 [insert_id] => 0 [num_rows] => 0 [param_count] => 12 [field_count] => 0 [errno] => 2031 [error] => No data supplied for parameters in prepared statement [error_list] => Array ( [0] => Array ( [errno] => 2031 [sqlstate] => HY000 [error] => No data supplied for parameters in prepared statement ) ) [sqlstate] => HY000 [id] => 6 )` – CoconuttMonkey Sep 30 '14 at 21:02
  • If you changed paid '?' to '0', have you removed the third 'i' from the end of your paramstring? The error that you've received regarding to paramstring and parameters count – Vahe Shadunts Sep 30 '14 at 21:06
  • FIXED!!! Just had to remove the `i` from `bind_param()` It now inserts the data to the table. Thanks for your help and talking me through it Vahe!! – CoconuttMonkey Sep 30 '14 at 21:07
  • see my last comment :) – Vahe Shadunts Sep 30 '14 at 21:07
  • Hahah, on the same page! – CoconuttMonkey Sep 30 '14 at 21:08