Display alert message and redirect the page












0














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>";
}









share|improve this question




















  • 2




    You've mixed up the PHP and JavaScript. Your if ($_SESSION... code is inside the previous echo command still, so it will not be processed correctly.
    – Kirk Beard
    Nov 13 '18 at 7:37
















0














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>";
}









share|improve this question




















  • 2




    You've mixed up the PHP and JavaScript. Your if ($_SESSION... code is inside the previous echo command still, so it will not be processed correctly.
    – Kirk Beard
    Nov 13 '18 at 7:37














0












0








0







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>";
}









share|improve this question















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>";
}






javascript php codeigniter






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 7:45









Krupesh Kotecha

2,05011134




2,05011134










asked Nov 13 '18 at 7:33









user5370838user5370838

4610




4610








  • 2




    You've mixed up the PHP and JavaScript. Your if ($_SESSION... code is inside the previous echo command still, so it will not be processed correctly.
    – Kirk Beard
    Nov 13 '18 at 7:37














  • 2




    You've mixed up the PHP and JavaScript. Your if ($_SESSION... code is inside the previous echo command still, so it will not be processed correctly.
    – Kirk Beard
    Nov 13 '18 at 7:37








2




2




You've mixed up the PHP and JavaScript. Your if ($_SESSION... code is inside the previous echo command still, so it will not be processed correctly.
– Kirk Beard
Nov 13 '18 at 7:37




You've mixed up the PHP and JavaScript. Your if ($_SESSION... code is inside the previous echo command still, so it will not be processed correctly.
– Kirk Beard
Nov 13 '18 at 7:37












3 Answers
3






active

oldest

votes


















2














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






share|improve this answer





















  • Yeah this is working
    – user5370838
    Nov 13 '18 at 9:14










  • Nice good job bro
    – j3thamz
    Nov 13 '18 at 9:24



















1














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>





share|improve this answer





























    1














    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>";





    share|improve this answer























    • i am getting error "Message: syntax error, unexpected '.' "
      – user5370838
      Nov 13 '18 at 7:44










    • The if has to be PHP code not JavaScript
      – Sebastian Speitel
      Nov 13 '18 at 7:48










    • I updated the code...
      – Simon
      Nov 13 '18 at 7:59











    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275967%2fdisplay-alert-message-and-redirect-the-page%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














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






    share|improve this answer





















    • Yeah this is working
      – user5370838
      Nov 13 '18 at 9:14










    • Nice good job bro
      – j3thamz
      Nov 13 '18 at 9:24
















    2














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






    share|improve this answer





















    • Yeah this is working
      – user5370838
      Nov 13 '18 at 9:14










    • Nice good job bro
      – j3thamz
      Nov 13 '18 at 9:24














    2












    2








    2






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






    share|improve this answer












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







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 13 '18 at 8:01









    j3thamzj3thamz

    764




    764












    • Yeah this is working
      – user5370838
      Nov 13 '18 at 9:14










    • Nice good job bro
      – j3thamz
      Nov 13 '18 at 9:24


















    • Yeah this is working
      – user5370838
      Nov 13 '18 at 9:14










    • Nice good job bro
      – j3thamz
      Nov 13 '18 at 9:24
















    Yeah this is working
    – user5370838
    Nov 13 '18 at 9:14




    Yeah this is working
    – user5370838
    Nov 13 '18 at 9:14












    Nice good job bro
    – j3thamz
    Nov 13 '18 at 9:24




    Nice good job bro
    – j3thamz
    Nov 13 '18 at 9:24













    1














    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>





    share|improve this answer


























      1














      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>





      share|improve this answer
























        1












        1








        1






        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>





        share|improve this answer












        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>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 7:53









        Kinjal PathakKinjal Pathak

        1045




        1045























            1














            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>";





            share|improve this answer























            • i am getting error "Message: syntax error, unexpected '.' "
              – user5370838
              Nov 13 '18 at 7:44










            • The if has to be PHP code not JavaScript
              – Sebastian Speitel
              Nov 13 '18 at 7:48










            • I updated the code...
              – Simon
              Nov 13 '18 at 7:59
















            1














            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>";





            share|improve this answer























            • i am getting error "Message: syntax error, unexpected '.' "
              – user5370838
              Nov 13 '18 at 7:44










            • The if has to be PHP code not JavaScript
              – Sebastian Speitel
              Nov 13 '18 at 7:48










            • I updated the code...
              – Simon
              Nov 13 '18 at 7:59














            1












            1








            1






            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>";





            share|improve this answer














            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>";






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 13 '18 at 7:56

























            answered Nov 13 '18 at 7:39









            SimonSimon

            566




            566












            • i am getting error "Message: syntax error, unexpected '.' "
              – user5370838
              Nov 13 '18 at 7:44










            • The if has to be PHP code not JavaScript
              – Sebastian Speitel
              Nov 13 '18 at 7:48










            • I updated the code...
              – Simon
              Nov 13 '18 at 7:59


















            • i am getting error "Message: syntax error, unexpected '.' "
              – user5370838
              Nov 13 '18 at 7:44










            • The if has to be PHP code not JavaScript
              – Sebastian Speitel
              Nov 13 '18 at 7:48










            • I updated the code...
              – Simon
              Nov 13 '18 at 7:59
















            i am getting error "Message: syntax error, unexpected '.' "
            – user5370838
            Nov 13 '18 at 7:44




            i am getting error "Message: syntax error, unexpected '.' "
            – user5370838
            Nov 13 '18 at 7:44












            The if has to be PHP code not JavaScript
            – Sebastian Speitel
            Nov 13 '18 at 7:48




            The if has to be PHP code not JavaScript
            – Sebastian Speitel
            Nov 13 '18 at 7:48












            I updated the code...
            – Simon
            Nov 13 '18 at 7:59




            I updated the code...
            – Simon
            Nov 13 '18 at 7:59


















            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53275967%2fdisplay-alert-message-and-redirect-the-page%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python