如果有标题,如何在PHP中使用javascript?

if(($row["status"])!="valid")
{
    $stats=$row["status"];
    echo "<script type='text/javascript'>";
    echo "alert('Your Status is $stats..Please Try Again Later...');";
    echo "</script>";
    header ("location: index.php");
}

it is a part of a php code. if i use // before header, javascript run..but when i don't use // , it goes to directly index.php. what is the solution?? OR is there is any way that i can call a javascript function for showing a message from this if condition??

In this scenario, Replace header with document.location.href So you can display an alertbox and when you click ok it redirects to your index.php page

if(($row["status"])!="valid")
{
    $stats=$row["status"];
    echo "<script type='text/javascript'>";
    echo "alert('Your Status is $stats..Please Try Again Later...');";
    echo "</script>";
    echo "<script>document.location.href='index.php'</script>";
}

Can you try this,

        <?php 
            if(isset($row["status"]) && trim($row["status"])!="valid")
            {
                    $stats=$row["status"];
                    echo "<script type='text/javascript'>";
                    echo "alert('Your Status is $stats..Please Try Again Later...');";
                    echo "window.location.href='index.php';"; // instead php header you can use javascript location.hrfe 
                    echo "</script>";                           
            }

        ?>
try

if(($row["status"])!="valid")
{
$stats=$row["status"];
echo "<script type='text/javascript'>";
echo "alert('Your Status is $stats..Please Try Again Later...');";
echo "</script>";
}
else{
header ("location: index.php");
}

You can also try like this

if(($row["status"])!="valid")
{
$stats=$row["status"];
echo "<script type='text/javascript'>";
echo "alert('Your Status is $stats..Please Try Again Later...');";
echo "location: index.php";
echo "</script>";
}