Xtrem fabz Xtrem fabz - 7 months ago 31
Javascript Question

javascript alert box not showing on php

I am trying to display an alert box before redirecting to another page, here is my code, when I remove the header function it works properly but when it is here it will just redirect to the page without showing the alert box.

<html>
<body>
<?php
include("dbconfig.php");

$tempid = mysqli_real_escape_string($dbconfig, $_POST['tempid']);

$sql_query = "DELETE FROM Visits
WHERE visitid = '$tempid'";
$result = Mysqli_query($dbconfig, $sql_query);
if ($result) {

echo '<script language="javascript">';
echo 'alert("visit deleted successfully")';
echo '</script>';

header("location:../SearchCountry/search.php");
}
?>
</body>
</html>

Answer
echo "<script>
alert('visit deleted successfully');
window.location.href='SearchCountry/search.php';
</script>";

and get rid of redirect line below.

You were mixing up two different worlds.