I have a small problem with PHP, I need to redirect the user, but I wanted to notify you of what happened, I redirect it with header()
, but if I try to send something before header
fails, Any tips on how I can send a message to usuario
and modify header
? I tried to change the header
before sending the message, but in this case the message was not sent.
Here is the code I made, I'm using MySql and wanted to notify the user when it was registered and when there was a failure:
<?php
error_reporting(E_ALL);ini_set('display_errors', 1);
$host = "localhost:8889";
$user = "root";
$pass = "root";
$banco = "ArrayEnterprises";
$conexao = mysqli_connect($host, $user, $pass, $banco);
$nome = $_POST["nome"];
$email = $_POST["email"];
$senha = md5($_POST["senha"]);
$img = $_POST["img"];
$inserir = "INSERT INTO Usuario (nome, email, senha, foto) VALUES('{$nome}', '{$email}', '{$senha}', '{$img}')";
if($query = mysqli_query($conexao, $inserir)){
if(mysqli_affected_rows($conexao) > 0){
header("location: index.html");
echo"<script language='javascript' type='text/javascript'>alert('Cadastrou!');</script>";
}
} else {
echo"<script language='javascript' type='text/javascript'>alert('houve um erro');</script>";
header("location: cadastro.html");
}
mysqli_close($conexao);
?>