hi guys, i am making a new app in cakephp (and i am new to the framework.. learned how to use it last night).. and i am supposed to make a signup system and login system but i am stuck in the signup.
i Worte the models and controllers and even the template for the signup but the system can't save the submitted data:
here are the codes..
=> Module: (user.php)

<?php
class User extends AppModel{
    var $name = "User";
}

=> UsersController.php

<?php
class UsersController extends AppController{
    var $name = "Users";
    function index(){
        $this->set("users", $this->User->find("all"));
    }

    function signup(){
       if(!empty($this->data)){
           if($this->User->save($this->data)){

               $this->Session->setFlash("Signup Complete!!");
               $this->redirect(array("controller"=>"pages", "action"=>"index"));
           }
           else
           {
                $this->Session->setFlash("An error has occured. Please Try again");
               $this->redirect(array("controller"=>"users", "action"=>"signup"));

           }
       }



       }
    function login(){

           }
}

and here is my signup.ctp

<?php include "../includes/header.php"; ?>
<section id="registration">
<h2>Register</h2>
<small>Register Now and enjoy with all the ATLANCER.NET's features!</small>
<?php
echo $this->form->create("Users", array("action"=>"signup"));
echo $this->form->input("email");
echo $this->form->input("password");
echo $this->form->input("nationality");
echo $this->form->input("phone");
echo $this->form->end("Sign up!");
?>
</section>

and this is my database table:

CREATE TABLE IF NOT EXISTS `users` (
  `id` int(255) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `address` varchar(255) NOT NULL,
  `credit` int(255) NOT NULL DEFAULT '5',
  `name_url` varchar(255) NOT NULL,
  `signup_date` datetime NOT NULL,
  `nationality` varchar(255) NOT NULL DEFAULT 'Rwandan',
  `birth_year` int(4) NOT NULL,
  `birth_month` int(2) NOT NULL,
  `birth_day` int(2) NOT NULL,
  `dream` text NOT NULL,
  `number_of_bids` int(255) NOT NULL,
  `number_of_work_done` int(255) NOT NULL,
  `rank` int(2) NOT NULL DEFAULT '1',
  `atrank` int(2) NOT NULL,
  `categories` int(11) NOT NULL,
  `awards` int(255) NOT NULL,
  `awards_given` text NOT NULL,
  `logins` int(255) NOT NULL,
  `phone` int(255) NOT NULL,
  `sms_enables` int(1) NOT NULL DEFAULT '0',
  `new_letter` int(1) NOT NULL DEFAULT '1',
  `upline` int(255) NOT NULL,
  `downlines` int(255) NOT NULL,
  `bank_account_number` varchar(255) NOT NULL,
  `backup_email` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

so what is wrong in my code above? It should work fine but it is totally not working! i submit data and it just doesn't store them into the database!
and also is there a way to manually store these data into the database?

You need to create an array of all datas before save. Try to do like this:

$arr['name'] = trim($this->data('name'));
$arr['email'] = $this->data('email');
$arr['address'] = $this->data('address');

........................................
and so on

And then
$this->User->save($arr);

Hope this will work. BTW have you set up your database.php in app/config? Please check it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.