Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7608395
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:54:08+00:00 2026-05-31T00:54:08+00:00

I am using Yii framework and I want to make a registration page. I

  • 0

I am using Yii framework and I want to make a registration page. I have created everything that was needed and when I register user I am getting no error at all but I can’t find a record in database. so can you help me? here is my code:

SiteController.php :

public function actionRegister()
{
    $model=new RegisterForm;

    // uncomment the following code to enable ajax-based validation

    if(isset($_POST['ajax']) && $_POST['ajax']==='register-form')
    {
        echo CActiveForm::validate($model);
        Yii::app()->end();
    }

    if(isset($_POST['RegisterForm']))
    {
        $model->attributes=$_POST['RegisterForm'];
        if($model->validate())
        {
            $user = new User;
            $user->username = $_POST['RegisterForm']['username'];
            $this->password = $_POST['RegisterForm']['password'];
            $this->salt = Security::GenerateSalt(128);
            $user->password = hash('sha512', $password.$salt);
            $user->question = $_POST['RegisterForm']['question'];
            $user->answer = $_POST['RegisterForm']['answer'];
            $user->salt = $salt;
            $user->email = $_POST['RegisterForm']['email'];
            $user->fullname = $_POST['RegisterForm']['fullname'];
            $user->birth = $_POST['RegisterForm']['dd'].'/'.$_POST['RegisterForm']['mm'].'/'.$_POST['RegisterForm']['yy'];
            $user->avatar = CUploadedFile::getInstance($model,'image');
            $user->about = $_POST['RegisterForm']['about'];
            $user->sighnup = date('d/m/y');
            $user->login = date('d/m/y');
            if($user->save())
            {
                $model->image->saveAs('images/users/localFile.jpg');
                // redirect to success page
            }

            $activation = new Activation;
            $record = User::model()->findByAttributes(array('username'=>$_POST['RegisterForm']['username']));
            $activation->user = $record->id;
            $activation->code = Security::ActivationCode(32);
            $activation->save();
        }
    }
    $this->render('register',array('model'=>$model));
}

RegisterForm.php a verification model:

class RegisterForm extends CFormModel
{
    public $username;
    public $password;
    public $password2;
    public $question;
    public $answer;
    public $email;
    public $fullname;
    public $avatar;
    public $about;
    public $dd;
    public $mm;
    public $yy;
    public $verifyCode;

    public function rules()
    {
        return array(
            array('username, password, password2, question, answer, email, fullname, dd, mm, yy', 'required'),

            array('username','length','min'=>4),
            array('username','length','max'=>16),
            array('username', 'filter', 'filter'=>'strtolower'),
            array('username', 'ext.alpha', 'allowSpaces'=>'flase', 'allowNumbers'=>'true', 'allAccentedLetters'=>'false'),
            array('username', 'unique', 'attributeName'=> 'username', 'className'=>'User' ,'caseSensitive' => 'false'),

            array('password', 'length', 'min' =>6),
            array('password', 'length', 'max' =>32),
            array('password2', 'compare', 'allowEmpty' => 'false', 'compareAttribute' => 'password'),

            array('question', 'length', 'min' =>10),
            array('question', 'length', 'max' =>128),

            array('answer', 'length', 'min' =>4),
            array('answer', 'length', 'max' =>64),

            array('email', 'length', 'min' =>8),
            array('email', 'length', 'max' =>128),
            array('email', 'email'),
            array('email', 'unique', 'attributeName'=> 'email', 'className'=>'User' ,'caseSensitive' => 'false'),

            array('fullname','length','min'=>6),
            array('fullname','length','max'=>64),
            array('fullname', 'ext.alpha', 'allowNumbers'=>'false', 'allowSpaces'=>'true', 'allAccentedLetters'=>'false'),

            array('avatar', 'file', 
                                'types'=>'jpg, gif, png', 
                                'maxSize'=>1024 * 1024 * 2,
                                'tooLarge'=>'The file was larger than 2MB. Please upload a smaller file.',
                                'wrongType'=>'Please upload only images in the format jpg, gif, png',
                                'tooMany'=>'You can upload only 1 avatar',
                        'on'=>'upload'),

            array('about','length','max'=>384),

            array('dd', 'numerical', 'allowEmpty'=>'false', 'integerOnly'=>'true', 'min'=>'1', 'max'=>'31'),
            array('dd', 'FilterDay'),
            array('mm', 'numerical', 'allowEmpty'=>'false', 'integerOnly'=>'true', 'min'=>'0', 'max'=>'12'),
            array('mm', 'FilterMonth'),
            array('yy', 'numerical', 'allowEmpty'=>'false', 'integerOnly'=>'true', 'min'=>'1900', 'max'=>'2008'),
            array('yy', 'FilterYear'),

            array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),
        );
    }

    public function attributeLabels()
    {
        return array(
            'username' => 'Username',
            'password' => 'Passwrod',
            'password2' => 'Verify Password',
            'email' => 'Email',
            'fullname' => 'Full Name',
            'dd' => 'Day',
            'mm' => 'Month',
            'yy' => 'Year',
        );
    }
}

Register.php a view file:

<div class="form">
<h1><?php echo($data); ?></h1>
<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'register-form',
    'enableAjaxValidation'=>true,
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>

    <div class="row">
        <?php echo $form->labelEx($model,'username'); ?>
        <?php echo $form->textField($model,'username'); ?>
        <?php echo $form->error($model,'username'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'password'); ?>
        <?php echo CHtml::activePasswordField($model,'password'); ?>
        <?php echo $form->error($model,'password'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'password2'); ?>
        <?php echo CHtml::activePasswordField($model,'password2'); ?>
        <?php echo $form->error($model,'password2'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'email'); ?>
        <?php echo $form->textField($model,'email'); ?>
        <?php echo $form->error($model,'email'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'fullname'); ?>
        <?php echo $form->textField($model,'fullname'); ?>
        <?php echo $form->error($model,'fullname'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'question'); ?>
        <?php echo $form->textField($model,'question'); ?>
        <?php echo $form->error($model,'question'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'answer'); ?>
        <?php echo $form->textField($model,'answer'); ?>
        <?php echo $form->error($model,'answer'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'avatar'); ?>
        <?php echo CHtml::activeFileField($model, 'avatar'); ?>
        <?php echo $form->error($model,'avatar'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'about'); ?>
        <?php echo CHtml::activeTextArea($model, 'about'); ?>
        <?php echo $form->error($model,'about'); ?>
    </div>

<?php
function getYear($value1 = 1900, $value2 = 2008)
{
    $data = array();

    for ($i = $value2; $i >= $value1; $i--){
        $data[$i] = (string)$i;
    }
    return $data;
}

function getMonth()
{
    $data = array();

    for ($i = 1; $i <= 12; $i++){
        $data[$i] = (string)$i;
    }
    return $data;
}

function getDays()
{
    $data = array();

    for ($i = 1; $i <= 31; $i++){
        $data[$i] = (string)$i;
    }
    return $data;
}
?>

    <div class="row">
        <?php echo $form->labelEx($model,'dd'); ?>
        <?php echo CHtml::activeDropDownList($model,'dd', getDays()); ?>
        <?php echo $form->error($model,'dd'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'mm'); ?>
        <?php echo CHtml::activeDropDownList($model,'mm', getMonth()); ?>
        <?php echo $form->error($model,'mm'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'yy'); ?>
        <?php echo CHtml::activeDropDownList($model,'yy', getYear()); ?>
        <?php echo $form->error($model,'yy'); ?>
    </div>

    <?php if(extension_loaded('gd')): ?>
    <div class="simple">
        <?php echo CHtml::activeLabel($model,'verifyCode', array('style'=>'width:150px;')); ?>
        <div>
        <?php $this->widget('CCaptcha'); ?>
        <?php echo CHtml::activeTextField($model,'verifyCode'); ?>
        </div>
        <p class="hint">Please enter the letters as they are shown in the image above.
        <br/>Letters are not case-sensitive.</p>
    </div>
    <?php endif; ?>

    <div class="row buttons">
        <?php echo CHtml::submitButton('Submit'); ?>
    </div>

<?php $this->endWidget(); ?>

</div><!-- form -->

I am getting no errors at all but the fact is that there is no post in database at all, please help me

——————————————————–Edited———————————————————————

I found out what was the problem. the problem is that I can’t insert an information in database via active record. When I type:

$user = new User;
$user->username = 'irakli';
$user->save();

it runs without errors but it doesn’t insert anything in database. But the fact is that Database connection is active because I can read raws from database via Active Record, the problem is that I can’t insert a new data in database via Active Record.

So any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:54:09+00:00Added an answer on May 31, 2026 at 12:54 am

    Try this:

    $user = new User;
    $user->username = 'irakli';
    if ($user->save())
    {
      echo "user record saved to the db";
    }
    else
    {
      var_dump($user->getErrors());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the yii framework and have different user accounts. When I want
I am developing a web page using Yii framework, I want to do url
I am using a script that runs on the YII framework... I have this
I am using Yii framework and I want to create a user login system
I'm trying to implement user registration using yii ActiveRecord. the problem is that every
I am using Yii framework, and I have a problem with redirect. I want
I am using PHP Yii Framework with MongoDB(yiimongodbsuite). I have created a Model which
I'm using the Yii framework. I want to show specific content if a user
I'm developing a CMS using Yii Framework. In developing the theme I have a
We've been developing a web application (PHP, using the Yii PHP framework) that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.