Trigger with data replacement by PHP and MySqL

Viewed 45

The code below is postar.php

include "conexao.php";

$consulta = mysqli_query($conexao, "SELECT titus.titus, titus.des, titus.link from titus");

while($postagem = mysqli_fetch_object($consulta));
echo "<div> $postagem-></div>
      <div>
      $postagem->
      $postagem->$postagem-></div>"

This one below is podcast.php

<!-- Button -->
<form method="post" action="postar.php">
 <button  type="submit" class="pos" >
publish</button>
</form>

I need to click on the publish button, so that it contains the latest information from the mysql database and returns it in a post.

In postar.php has a small php code, which aims to replace the information that is titus, des and link

example:

titus is sun
des is moon
link is land

(data in the database)

so it should look like this:

sun
moon
land

But when I run the code, only the arrows appear. I want to know how to solve this and appear the data as a post.

Below contains the database connection code, which is conexao.php

define('HOST', '127.0.0.1');
define('USUARIO', 'root');
define('SENHA', '');
define('DB', 'login');

$conexao = mysqli_connect(HOST, USUARIO, SENHA, DB) or die ('Could not connect');

And this is the database table:

CREATE TABLE titus(
idpod INT NOT NULL AUTO_INCREMENT,
titus VARCHAR(200) NOT NULL,
des VARCHAR(400) NOT NULL,
link VARCHAR (300) NOT NULL,
PRIMARY KEY (`idpod`)
);

This code aims to make a post, where when adding a new record in the database, I do this posting process, I know that somehow it is possible to do this with trigger, I am not a professional programmer, but I would like to understand this question, thank you all :)

2 Answers

you should change your code, like this:

$consulta = mysqli_query($conexao, "SELECT titus, des, link from titus");

while($postagem = mysqli_fetch_object($consulta));

if ($postagem) {
    echo "<div>titus is $postagem->titus</div>
      <div>des is $postagem->des</div>
      <div>link is $postagem->link</div>";
} else {
    echo "data is empty";
}

This code worked:

$consulta = mysqli_query($conexao, "SELECT * from titus
where idpod = (select max(idpod) from titus)");

while($postagem = mysqli_fetch_object($consulta)){

     echo $postagem = $_POST['titus'] .'<br>';
     echo $postagem = $_POST['des'] .'<br>';
     echo $postagem = $_POST['link'] .'<br>';
Related