rand() is not working right (email activation problem)

[font=“Verdana”]I guess this is not a Yii problem but I decided to ask it here. I have registration code which have simple activation code system in it. I try to generate code with 5 numbers in it but it doesn’t work right. In email what’s sent to user have always different integer in it but the database (MySQL) always saves same code 32767 or something like that.

If you need more pieces of code, just ask.

UserController.php[/font]


    public function actionRegister()

    {

        $newUser = new User();

		$newCharacter = new Character();


        if($newUser->load(Yii::$app->request->post()) && $newCharacter->load(Yii::$app->request->post()))

		{

			if($newUser->validate() && $newCharacter->validate()) 

			{

					$newUser->emailActivated = 0;

					$newUser->registerIP = $_SERVER['REMOTE_ADDR'];

					$newUser->loginIP = $_SERVER['REMOTE_ADDR'];

					$newUser->setPassword($newUser->password);

					$newUser->setActivationCode();

				if($newUser->save())

				{

					$newCharacter->userID = $newUser->userID;

					

					$newStats = new Stats;

					$newStats->userID = $newUser->userID;


					if($newStats->save() && $newCharacter->save())

					{

						$activationLink = "link";

						Yii::$app->mailer->compose()

						->setFrom(['ADDRESS' => 'NAME'])

						->setTo($newUser->email)

						->setSubject('Welcome!')

						->setHtmlBody('<p><b>Welcome, '.$newUser->username.'!</b><br /><br />

												Your activation code is: <b>'.$newUser->activationCode.'</b>

												You can easily activate your email by clicking the following link:<br />

												'. $activationLink .'</p>')

						->send();

						

						return $this->redirect(['view', 'id' => $newUser->userID]);

					}

				}

			}

		}

		else {

            return $this->render('register', [

                'newUser' => $newUser,

				'newCharacter' => $newCharacter,

            ]);

        }

    }

[font="Verdana"]User.php[/font]


	public function setActivationCode()

	{

		srand(time(null));

		$this->activationCode = rand(10000, 99999);

	}

PS. I would also like to know how could I change saving format of TimestampBehavior. I would like to get those dates like 00-00-0000, not 00.00.0000 00.00.00.

Does your ‘activationCode’ column have a sufficient size to hold 99999?

(Isn’t it defined as a SHORT INT?)

[font="Verdana"]It was defined as "INT" only (because I thought I would change my activation system afterwards). I changed it to MEDIUMINT and now it seems working. Weird but at least it works. Thanks a lot![/font]