-2

I have php code, but insude that code I should call js alert() function. Is it possible? if yes, how can I do it?

if($findUserRow['active'] == 0){
        $message = "You should activate your account!";
        alert($message); //here should be pop up window
    }
  • Possible duplicate of [What is the difference between client-side and server-side programming?](http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – ChrisGPT was on strike Apr 28 '17 at 11:13
  • Try echo "" – Douglas Hosea Apr 28 '17 at 11:30
  • you cannot call, just redirect and thus make the client likely to call it, js can be blocked or ignored on client-side still – vv01f Apr 28 '17 at 12:40

4 Answers4

0
if($findUserRow['active'] == 0)
{
    ?>
    <script>
        var message = "You should activate your account!";
        alert(message); //here should be pop up window
    </script>
    <?php
}
Biju P Dais
  • 131
  • 1
  • 12
0

You can echo Javsacript to page like as below.

if($findUserRow['active'] == 0){
    $message = "You should activate your account!";
    echo "<script> alert(".$message.");</script>";
}
Murtaza Bhurgri
  • 398
  • 2
  • 9
0

You should always separate the backend logic from the frontend logic.

send variables from the back to the front, then process on the front. Ideally you want to use templates in php. Things can get messy.

<script>
var active = <?php echo $findUserRow['active']; ?>;
var message = "You should activate your account!";

if(active == false){
    alert(message);
}
</script>

Please focus on isolating the 2. It will give you more controlling generally.

A H Bensiali
  • 825
  • 1
  • 9
  • 22
0

Try this..

<?php
  $findUserRow['active']=0;
  if($findUserRow['active'] == 0){
    $message = "You should activate your account!";
?>
  <script>
    var msg = "<?php echo $message; ?>";
    alert(msg);
  </script>
<?php    
 }
?>
Ashok
  • 128
  • 1
  • 8