Information does not arrive in value attribute

1

The information I get in the user model (getTimeLine method) gets to the homeController, but does not arrive in 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);
}

<!-- 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 -->

    
asked by anonymous 12.11.2017 / 01:54

2 answers

0

Change the getTimeLine function 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 getTimeLine function you pass the POST ID (I believe it's from the post you get in the query) directly into the function:

$this->getTimeLine(12345);
    
12.11.2017 / 15:14
0

Try to create a select in the table, because what you are doing is meaningless, you are giving echo in practically nothing, as it does not have 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']; ?>" >
    
12.11.2017 / 14:40