Retrieves values using classes and pdo without going through the url

1

Good afternoon, I have a class where I pass all methods insert , update , delete , consulta(fechall) and consulta(fech($id))

Below I show the class of consulta(fech($id))

public function selId($id){
    $sqlId = "SELECT * FROM web_cadcli WHERE idcad_cliente = ':id_us', nom_cliente = $this->getNome($nome), ema_cliente = $this->getEmail($email), senha_email = $this->senha($senha)  ";
    $sqlId = $this->con->conectar()->prepare($sqlId);
    $sqlId->bindParam(':id_us', $this->cod,   PDO::PARAM_INT);
    $sqlId->bindParam(1,        $this->nome,  PDO::PARAM_STR);
    $sqlId->bindParam(2,        $this->email, PDO::PARAM_STR);
    $sqlId->bindParam(3,        $this->senha, PDO::PARAM_STR);
    $sqlId->execute();
    return ($sqlId->fetch(PDO::FETCH_ASSOC));
    }//retorna o Id do Usuario - testar

I want to fetch values in the database with ID and later retrieve it on my form

Below I show my form with the code where I need to retrieve the values.

<?PHP
        $Objeto = new Usuario(); 
        $usuario = $Objeto->selId(); ?><!--SELECIONO O ID DO METODOS selId-->

          <input name="id_ui" type="hidden" value="id_usu"/>
          <div class="form-group">

            <label for="exampleInputEmail1">Nome</label>
            <input type="nome" class="form-control" id="exampleInputEmail1" value="<?php $usuario->setNome($nome); ?>">
          </div>

          <div class="form-group">
            <label for="exampleInputPassword1">Email</label>
            <input type="email" class="form-control" id="exampleInputPassword1" value="<?php $usuario->setNome($nome) ?>">
          </div>

          <div class="form-group">
            <label for="exampleInputFile" disable>Imagem</label>
            <input type="file" id="exampleInputFile">
           </div>

          </form>
    
asked by anonymous 06.06.2017 / 21:57

1 answer

0

First you need to hit your query, or you named placeholders that are those have two colon followed by a name eg: :id or place holders that are the questions.

Change:

$sqlId = "SELECT * FROM web_cadcli WHERE idcad_cliente = ':id_us', nom_cliente = $this->getNome($nome), ema_cliente = $this->getEmail($email), senha_email = $this->senha($senha)  ";

To:

$sqlId = "SELECT * FROM web_cadcli
 WHERE idcad_cliente = ?, nom_cliente = ?, ema_cliente = ?, senha_email = ?";

The second step is to fix the binds, each interrogation must be 'roasted' with its position in the query. The first value should always start with one.

$sqlId->bindParam(1, $this->cod,   PDO::PARAM_INT);
$sqlId->bindParam(2, $this->nome,  PDO::PARAM_STR);
$sqlId->bindParam(3, $this->email, PDO::PARAM_STR);
$sqlId->bindParam(4, $this->senha, PDO::PARAM_STR);

Lastly, display the value of the object in the form, change set() to get() and put a echo or print before. Remember that the return of your query is a simple array and not an object

change:

<input type="email" class="form-control" id="exampleInputPassword1" value="<?php $usuario->setNome($nome) ?>">

To:

 <input type="email" class="form-control" id="exampleInputPassword1" value="<?php echo $usuario['nome']; ?>">
    
07.06.2017 / 19:28