2
I have a small problem with PHP, I need to redirect the user, but I wanted to notify you of what happened, I redirect you with the header()
, but if I try to send something before the header
failure, any hint as to how I can send a message to the usuario
and modify the header
? I tried to change the header
before sending the message, but in that case the message was not sent.
Here’s 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);
?>