0

I am just a newbie in cakephp and struggled a lot as a beginner, I hope im not exaggerating. I believe I was on the right track of coding a simple registration application when I found out that I am not able to insert any data in my database. The name of my database is "cake" and this is the default configuration:

public $default = array{
    'datasource'=>'Database/Mysql',
    'persistent'=>false,
    'host'=>'localhost',
    'login'=>'root',
    'password'=>'',
    'database'=>'cake',
    'schema'=>'',
    'prefix'=>''
}

By the way, the index page of my localhost says that I am connected to the database.

4

3 回答 3

0

try these

  • Your DB config tells me that you are using cakephp 2 +, use

$this->User->save($this->request->data);

  • Set your debug level higher than 0 in Config/core.php to see errors if they exist

  • Generally the save doesn't work because of validation. You can list invalid fields by

debug($this->User->invalidFields()); // will only show when debug > 0

  • The sql log in the bottom (only when debug > 0) will show the insert query, try pasting that query directly into mysql from your mysql front end. See if there are any errors over types, constraints.
于 2012-04-01T16:29:26.203 回答
0

Nobody seems to have mentioned this, but if your database config code is really what you posted, you should be getting a syntax error. I mean, this:

public $default = array{
    // ...
}

should be like this:

public $default = array(
    // ...
);
于 2012-04-01T21:23:53.350 回答
0

part of my code was actually something like this:

  <?php class UsersController extends AppController { 
  function register() { 
      if (!empty($this->params['form'])) { 
        if ($this->User->save($this->params['form'])) { 
          $this->flash('Your registration information was accepted.', '/users/register');
      }

      else { 
          $this->flash('There was a problem with your registration', '/users/register'); } } } } ?> 

What i did is I changed all the "$this->params['form']" to "$this->request->data". Worked like magic. :)

于 2012-04-07T02:32:58.700 回答