Information is not enough in the value attribute

Asked

Viewed 57 times

1

The information that I take from the user model (getTimeLine method) reaches the homeController, but does not reach the homeView in the input type Hidden in the value attribute.

public function perfil($id) {
    $dados = array();

    $p = new posts();

    if(isset($_POST['msg']) && !empty($_POST['msg'])) {

        $msg = addslashes($_POST['msg']);
        $time_line = addslashes($_POST['time_line']);
        $p->inserirPost($msg, $time_line);
    }

    $u = new usuarios($id);
    $dados['nome'] = $u->getNome();
    $dados['localizacao'] = $u->getLocalizacao();
    $dados['avatar'] = $u->getAvatar();
    $dados['feed'] = $u->getFeed();
    $dados['time_line'] = $p->getTimeLine();


    $this->loadTemplate('home', $dados);
}

Var_dump mostra que o valor esta preenchido na variável time_line.

<!-- Formulario -->
<div class="well">
	<h4 class="text-center">Redactar un nuevo Tweet</h4>
	<form method="POST" class="form-group">
		<textarea name="msg" class="form-control" rows="3"></textarea><br/>

		<input type="hidden" name="time_line" value="<?php echo $time_line; ?>">

		<input type="submit" value="Twittear" class="btn btn-primary" />
	</form>
</div>
<!-- End formulario -->

Atributo value vazio.

inserir a descrição da imagem aqui

  • Put the code here and the images, it is simpler than asking someone to enter another location to verify your error

  • The first image is output from that variable ?

  • The first image is a var_dump of the $data array that is in the controller, in this array has everything I need to show in the view. The second image shows the view source code, where everything in $data is printed, minus the time_line variable in the Hidden input.

2 answers

0

Try to create a select in the table, because what you are doing has no sense, you are echo in virtually nothing, because there is no time_line defined as variable understand, therefore try an example like this below

<?php 
    $sql = "SELECT * FROM time_line";
    $resultado = mysqli_query($conn, $result); 
    $dados = = mysqli_fetch_assoc($resultado);
?>

<input type="hidden" name="time_line"  value="<?php echo $dados['time_line']; ?>" >
  • Sorry, I forgot to show the photo of my query. I will publish it now.

  • Then you will have to put this query in the form page and take the value as indicated, because only giving echo in the variable will not work

  • What is confusing for me is because I could so far bring other information like: avatar, location, name and only this variable does not want to appear.

  • Tried to do as I said ? indicate the error that appears when you do this way please... Remove from Hidden and put text and if error appears inside Hidden you will know what is happening

0


Change the function getTimeLine that you have for this:

public function getTimeLine($id){

    $sql = "SELECT time_line FROM posts WHERE id = '".$id."'";
    $query = $this->db->query($sql);

    if($query->rowCount() > 0){

        $row = $query->fetch();

        return $row['time_line'];
    }
}

Now every time you call the function getTimeLine you pass the POST ID (I believe it is from the post you take in the query) directly in the function:

$this->getTimeLine(12345);
  • I got it, I found the problem. That’s about it, Alisson. I have a column in the table posts called id_usuario, which is always equal to the id column of the user table. The problem was in the query, with the correction, other problems appeared, which were solved.

Browser other questions tagged

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