How to put more than one Get method along with the sql code to send the information in the bd ? Example: Put email and password

Asked

Viewed 31 times

-1

Php user.

    #Conexao/categoria.php
    include_once 'conexao.php';

    class UsuarioDAO{
        public function Inserir(Usuario $usu){
            try{
                if (!empty($usu->getNome())){
                    $sql = "INSERT INTO usuario (nome) VALUES (:n)";

                    $sp_sql = Conexao::getInstance()->prepare($sql);

                    $sp_sql->bindValue(":n", $usu->getNome());

                    return $sp_sql->execute();
                }
                else{
                    return false;
                }

            } catch (Exception $e){
                print $e->getMessage();
            }
        }

userObj.php

<?php
    //Controller/categoriaObj.php
    include_once '..\Model\usuario.php';
    include_once '..\Conexao\usuario.php';

    $id = $_POST['id'];
    $nome = $_POST['nome'];
    $email = $_POST['email'];
    $senha = $_POST['senha'];

    //instanciar o objeto
    $usu = new Usuario($id, $nome, $email, $senha);
    $usuDAO = new UsuarioDAO();

    //Chamar o método para mostrar a tabuada
    $usuDAO->Inserir($usu);
?>
  • you need to be clearer, your question is too vague.

1 answer

0


I will try to help, I imagine that "putting another Get method" is something related to the Gets of the attributes of the User class. Since you have a getName() and you need to add an email, I imagine you have a getEmail() method in your User class and also an email field in your database (I’m just guessing that’s your question).

If I have understood correctly, in your code can be done something like below:

$sql = "INSERT INTO usuario (nome, email) VALUES (:n, :e)";

                $sp_sql = Conexao::getInstance()->prepare($sql);

                $sp_sql->bindValue(":n", $usu->getNome());
                $sp_sql->bindValue(":e", $usu->getEmail());

Note that for each column in the database, as you are using bindValues, you must create a parameter for each one.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.