donjakobo/A3M

Sign up under HMVC - A Database Error Occurred

Closed this issue · 5 comments

Hi, I converted A3M from MVC to HMVC. Everything works fine, but when I create a new account, account/sign_up says this:

A Database Error Occurred
You must use the "set" method to update an entry.

Filename: C:\wamp\www\mmfv2\system\database\DB_active_rec.php

Line Number: 1272

However, the system creates the new account and when I use the email and password I can access the user area. Would you know how to approach this error?

Thanks,
Jakub

So I was digging deeper and the problem is in account_details_model.php

Concretely here:

var_dump($attributes);
if ($this->get_by_account_id($account_id)){
var_dump($attributes);
$this->db->where('account_id', $account_id);
$this->db->update('a3m_account_details', $attributes);
}

First var_dump return correct attributes, however when inside IF, it returns EMPTY.

What version of CodeIgniter are you using?

I am using 2.1.3, but I guess I have resolved the problem myself now. I had a version of A3M from this January running and during the upgrade it started showing this error. I guess I missed something in my custom code. It started working now when I replaced the files completely. You can close this topic.

Glad to hear that! Please share with us any fixes you make to the code.

Ok, there is something I can share with you regarding the sign_up. I was thinking a lot whether users should enter their username the first thing during the registration or it should be rather in line with Facebook and other services where username is the icing on the cake and what matters first in their real name. I have have edited A3M so that username is not necessary during the registration, but is dynamically created for the user and passed to the $this->account_model->create ().

Line 70 of the sign_up controller: find and replace the create section
// Create user
$username = preg_replace("/[^A-Za-z0-9 ]/", '', $this->input->post('sign_up_firstname', TRUE) . $this->input->post('sign_up_lastname', TRUE).substr(uniqid(), 6, 6));
$user_id = $this->account_model->create($username, $this->input->post('sign_up_email', TRUE), $this->input->post('sign_up_password', TRUE));

In sign_up view replace the username area with this:

                <div class="control-group <?php echo (form_error('sign_up_firstname') || isset($sign_up_firstname_error)) ? 'error' : ''; ?>">
                    <label class="control-label" for="sign_up_firstname"><?php echo lang('sign_up_firstname'); ?></label>

                    <div class="controls">
                        <?php echo form_input(array('name' => 'sign_up_firstname', 'id' => 'sign_up_firstname', 'value' => set_value('sign_up_firstname'), 'maxlength' => '24')); ?>
                        <?php if (form_error('sign_up_firstname') || isset($sign_up_firstname_error)) : ?>
                            <span class="help-inline">
                            <?php echo form_error('sign_up_firstname'); ?>
                            <?php if (isset($sign_up_firstname_error)) : ?>
                                <span class="field_error"><?php echo $sign_up_firstname_error; ?></span>
                            <?php endif; ?>
                            </span>
                        <?php endif; ?>
                    </div>
                </div>

                <div class="control-group <?php echo (form_error('sign_up_lastname') || isset($sign_up_lastname_error)) ? 'error' : ''; ?>">
                    <label class="control-label" for="sign_up_lastname"><?php echo lang('sign_up_lastname'); ?></label>

                    <div class="controls">
                        <?php echo form_input(array('name' => 'sign_up_lastname', 'id' => 'sign_up_lastname', 'value' => set_value('sign_up_lastname'), 'maxlength' => '24')); ?>
                        <?php if (form_error('sign_up_lastname') || isset($sign_up_lastname_error)) : ?>
                            <span class="help-inline">
                            <?php echo form_error('sign_up_lastname'); ?>
                            <?php if (isset($sign_up_lastname_error)) : ?>
                                <span class="field_error"><?php echo $sign_up_lastname_error; ?></span>
                            <?php endif; ?>
                            </span>
                        <?php endif; ?>
                    </div>
                </div>

sign_up controller change the form_validation:

$this->form_validation->set_rules(array(
array('field' => 'sign_up_firstname', 'label' => 'lang:sign_up_firstname', 'rules' => 'trim|required|min_length[2]'),
array('field' => 'sign_up_lastname', 'label' => 'lang:sign_up_lastname', 'rules' => 'trim|min_length[2]'),
array('field' => 'sign_up_password', 'label' => 'lang:sign_up_password', 'rules' => 'trim|required|min_length[6]'),
array('field' => 'sign_up_email', 'label' => 'lang:sign_up_email', 'rules' => 'trim|required|valid_email|max_length[160]')));

and that's it....easy peasy and users won't be frustrated with "which username to choose" dilemma anymore.

I am a hobby programmer, so use on your own risk :-)