We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

my db don't take what my form provide him

Hello

I'm having a really weird problem with my database and can't manage to solve it.

  • I'm creating a user with a form
  • My controller receive what my form send him
  • A user appear in my database but only the email have been registered

here is a better view of the problem:

img

img

here is my controller :

    public function createAction(){
        if (!$this->request->isPost()) {
            this->dispatcher->forward([
                'controller' => "users",
                'action' => 'index'
            ]);
            return;
        }

        $user = new Users();
        $user->setlastName($this->request->getPost("LastName"));
        $user->setfirstName($this->request->getPost("FirstName"));
        $user->setlogin($this->request->getPost("Login"));
        $user->setpassword($this->request->getPost("password"));
        $user->seteMail($this->request->getPost("eMail"));

        var_dump($this->request->getPost("LastName"));
        var_dump($this->request->getPost("FirstName"));
        var_dump($this->request->getPost("Login"));
        var_dump($this->request->getPost("Password"));
        var_dump($this->request->getPost("eMail"));

        var_dump($user);

        if (!$user->save()) {
            foreach ($user->getMessages() as $message) {
                $this->flash->error($message);
                var_dump($message);
            }

            $this->dispatcher->forward([
                'controller' => "users",
                'action' => 'new'
            ]);

            return;
        }

        $this->flash->success("user was created successfully");

        $this->dispatcher->forward([
            'controller' => "users",
            'action' => 'index'
        ]);
    }

here is my form :

        <div class="row">
            <nav>
                <ul class="pager">
                    <li class="previous"><?php echo $this->tag->linkTo(["users", "Go Back"]) ?></li>
                </ul>
            </nav>
        </div>

        <div class="page-header">
            <h1>
                Create users
            </h1>
        </div>

        <?php echo $this->getContent(); ?>

        <?php
            echo $this->tag->form(
                [
                    "users/create",
                    "class" => "form-horizontal"
                ]
            );
        ?>

        <div class="form-group">
            <label for="fieldLastname" class="col-sm-2 control-label">LastName</label>
            <div class="col-sm-10">
                <?php echo $this->tag->textField(["LastName", "cols" => 30, "rows" => 4, "class" => "form-control", "id" => "fieldLastname"]) ?>
            </div>
        </div>

        <div class="form-group">
            <label for="fieldFirstname" class="col-sm-2 control-label">FirstName</label>
            <div class="col-sm-10">
                <?php echo $this->tag->textField(["FirstName", "cols" => 30, "rows" => 4, "class" => "form-control", "id" => "fieldFirstname"]) ?>
            </div>
        </div>

        <div class="form-group">
            <label for="fieldLogin" class="col-sm-2 control-label">Login</label>
            <div class="col-sm-10">
                <?php echo $this->tag->textField(["Login", "size" => 30, "class" => "form-control", "id" => "fieldLogin"]) ?>
            </div>
        </div>

        <div class="form-group">
            <label for="fieldPassword" class="col-sm-2 control-label">Password</label>
            <div class="col-sm-10">
                <?php echo $this->tag->passwordField(["Password", "size" => 30, "class" => "form-control", "id" => "fieldPassword"]) ?>
            </div>
        </div>

        <div class="form-group">
            <label for="fieldEmail" class="col-sm-2 control-label">EMail</label>
            <div class="col-sm-10">
                <?php echo $this->tag->textField(["eMail", "size" => 30, "class" => "form-control", "id" => "fieldEmail"]) ?>
            </div>
        </div>

        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <?php echo $this->tag->submitButton(["Save", "class" => "btn btn-default"]) ?>
            </div>
        </div>

        <?php echo $this->tag->endForm(); ?>

Hi check your PDO configurations and use a query profiler to see what is being sent to the db. After that tell us what do yo get. Good luck