1
I am working on a simple message system, and it works, but whenever a refresh is given on the page, the information of the last Internet is sent back to the database. And if nothing has been filled, and it has been given refresh it simply sends an empty value to the database, as if leaving the page and going back to it are sent the empty values in the same way. I researched a lot on google and tested several things, but nothing worked so far, I found some that tried to undo replicated data, but in this case I would like to be sent duplicate anyway if it is done by user Ubmit. Does anyone know if they can tell the difference between Ubmit and Refresh?
I put an image demonstrating the page and the error message that appears when F5 is given, this is not unique to firefox. The blank messages with a blank name are what I said before.
Follows the code:
Danilo Macedo Bakun
<div id="tudo">
<form id="formulario" action="comentarios.php" method="POST">
<h1>Nome:</h1>
<input type="text" id="nome" name="Nome" required><br>
<h1>Mensagem: </h1><br>
<textarea id="mensagem" name="Mensagem" required></textarea><br>
<input type="submit" name="enviar" value="Enviar">
</form>
<?php
$strcon = mysqli_connect('localhost','root','','teste') or die('Erro ao conectar ao banco de dados');
if (isset($_POST['Nome']) === true)
{
$nome = $_POST['Nome'];
} else {
$nome = false;
}
if (isset($_POST['Mensagem']) === true)
{
$mensagem = $_POST['Mensagem'];
} else {
$mensagem = false;
}
$sql = "INSERT INTO mensagem VALUES ('$nome', '$mensagem')";
mysqli_query($strcon,$sql) or die("Erro ao tentar cadastrar registro");
$consulta = "SELECT * FROM mensagem";
$sqlc = mysqli_query($strcon,$consulta) or die("Erro ao tentar consultar registro");
while($aux = mysqli_fetch_assoc($sqlc))
{
echo "<h1>-----------------------------------------</h1><br>";
echo "<h1>Nome: ".$aux["nome"]."</h1><br>";
echo "<h1>Mensagem:".$aux["mensagem"]."</h1><br>";
}
mysqli_close($strcon);
?>
</div>
</body>
I managed to resolve using another php page, thank you very much for the help.
– DaniloMB