Q:

Alert box not working with php

<? 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? 

A:

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>

