user5370838
user5370838

Reputation: 111

Display alert message and redirect the page

I have the following code. On failure i need to get the alert Already exists and redirect to te registration page. But on success i need to check the session and based on the role id i need to redirect the page but the alert and redirection is not happening in this case ... can you please tell where i am wrong

if ($referral_patient_id != NULL) {
    echo "<script language='javascript'>
    alert('Successfully Added');
    if ($_SESSION['role_id'] != 6) {
        echo 'window.location.href="../Laboratory_Home"';
    } else {
        echo 'window.location.href="../Billing_Home"';
    } </script>";
} else {
    echo "<script language='javascript'>
    alert('Already Exists');
    window.location.href = '../../LabAdd_Patients'; 
    </script>";
}

Upvotes: 0

Views: 1163

Answers (3)

j3thamz
j3thamz

Reputation: 66

<?php if ($referral_patient_id != NULL) { ?>
    <script type='javascript'>
    alert('Successfully Added');
<?php  if ($_SESSION['role_id'] != 6) { ?>
     window.location.href="../Laboratory_Home";

<?php } else {  ?>
       window.location.href="../Billing_Home";
<?php  }  ?>
</script>
  <?php  }else { ?>
      <script type='javascript'>
         alert('Already Exists');
        window.location.href = '../../LabAdd_Patients'; 
  </script>
   <?php } ?>

Try this one dude.

Upvotes: 2

Simon
Simon

Reputation: 128

You have mixed content. PHP and Javascript. Try this one

echo "<script language='javascript'>
        alert('Successfully Added');
     </script>";

if($_SESSION['role_id']!=6){
  echo "<script language='javascript'>window.location.href='../Laboratory_Home'</script>";
} else {
  echo "<script language='javascript'>window.location.href='../Billing_Home'</script>";
}

Or this one

echo "<script language='javascript'>
        alert('Successfully Added');
        if( ".$_SESSION['role_id']." !=6) {
            window.location.href='../Laboratory_Home';
        } else {
            window.location.href='../Billing_Home';
        }
    </script>";

Upvotes: 1

Kinjal Pathak
Kinjal Pathak

Reputation: 371

Try this javascript code :

<script language='javascript'>
var referral_patient_id = '<?php echo $referral_patient_id; ?>';
if(referral_patient_id != null)
{
    alert('Successfully Added');
    var role_id = '<?php echo $_SESSION["role_id"]; ?>';
    if (role_id != '6') {
        window.location.href="../Laboratory_Home";
    } else {
        window.location.href="../Billing_Home";
    }
} 
else
{
    alert('Already Exists');
    window.location.href = '../../LabAdd_Patients'; 
}
</script>

Upvotes: 1

Related Questions