How to return to the home page after an alert message

0

I have a page that performs an IMC calculation and saves some information in the bank.

The structure is divided into four files:
index.html = html code;
index.php = Calls index.html ;
banco.php = Connects to the database;
cadastrar.php = Performs the calculation, saves to the bank and returns the message

The IMC message is given by alert() . When I click on "Ok", the alert closes and I continue to the page all blank cadastrar.php (page that takes the data, does the calculation and returns the message of the user).


I tried to use location.href expiration and other options to try to redirect, but to no avail.

I would like to know how to do so that after I close alert() , the user returns to the index page?

session_start();
include "banco.php";


$nome = "";
$altura = 0;
$peso = 0;

if(!empty($_POST))
{
$nome = $_POST['nome'];
$altura = $_POST['altura'];
$peso = $_POST['peso'];

cadastrar($nome,$altura,$peso);
calcularIMC($altura,$peso);

}


function cadastrar($nome,$altura,$peso)
{
try
{
    $pdo = conectar();
    $incluir = $pdo->prepare("INSERT INTO usuario("
            . "nome, altura, peso) VALUES("
            . ":nome, :altura, :peso)");
    $incluir->bindValue(":nome", $nome);
    $incluir->bindValue(":altura", $altura);
    $incluir->bindValue(":peso", $peso);
    $incluir->execute();

    if($incluir->rowCount() > 0)
        return true;
    else
        return false;

}catch(PDOException $e)
{
   echo "Erro ao incluir na tabela categoria ".$e->getMessage();
}
}

function calcularIMC($altura,$peso){

$imc = 0;
if($altura >0 && $peso >0){
  $imc = $peso / ($altura * $altura);
}

echo '<script language="javascript">';
echo 'alert("Sua quantidade de IMC é: '.$imc.'")';
echo 'location.href="index.html"';  //Tentei utilizar o location.href, mas sem sucesso 
echo '</script>';

}
    
asked by anonymous 15.04.2016 / 20:19

1 answer

0

A semicolon is missing after the alert.

echo '<script language="javascript">';   
echo 'alert("Sua quantidade de IMC é: '.$imc.'");';
echo 'location.href="index.html";';    
echo '</script>';
    
15.04.2016 / 20:32