2

I don't understand how to pass a variable from PHP to a JavaScript function. I need to send a $flag value which is in the else part of my code.

Here is my code:

<html>
    <body>
    <script type="text/javascript" src="scripts/jquery-1.11.0.min.js"></script>
    <script type="text/javascript" src="scripts/chat.js"></script>

    <?php
    session_start();
    if (isset($_POST['msg'])) {
        require_once __DIR__ . '/../../core/FbChatMock.php';
        $userId = (int) $_SESSION['user_id'];

        // Escape the message string
        $msg = htmlentities($_POST['msg'],  ENT_NOQUOTES);

        $output= shell_exec("py c://xampp/htdocs/fbchat/public/chat.py $msg $userId "); 
        $out = preg_replace('/\s+/', '', $output);
        $sac="Ididnotunderstand,Doyouwantmetolearn[yes/no]";
        if(strcmp($out,$sac)==1)
        { 
            $Id = 2;
            $chat = new FbChatMock();
            $result = $chat->addMessage($Id, $output);

        }
        else 
        { 
            $Id = 2;
            $chat = new FbChatMock();  
            $result = $chat->addMessage($Id, $output);
            $flag   = 0;
            echo "run();"; 

        }   
    }
    }
CJ Dennis
  • 4,226
  • 2
  • 40
  • 69
Shiv
  • 105
  • 6
  • When you look at the page source client-side, what is output by this? In what way is it incorrect? – David Jun 18 '17 at 20:02

0 Answers0