<?php if ($data == "") { ?>
<script type="text/javascript">
alert("review your answer1");
window.location.href = "index1.php";
</script>
<?php } else { ?>
<script type="text/javascript">
alert("review your answer2");
window.location.href = "index2.php";
</script>
<?php } ?>
Alert box is not showing in above code as well as page is also not redirecting. What is wrong in it?
Do the other way around:
<script>
var data = <?php echo $data; ?>
if ( data === "" ) {
alert("review your answer1");
window.location.href = "index1.php";
} else {
alert("review your answer2");
window.location.href = "index2.php";
}
</script>
Improving your code, it may require some adaptation:
<script>
alert("review your answer<?echo $data;?>");
window.location.href = "index<?echo $data;?>.php";
</script>