This is is my php:


   echo '<h1>' . $_POST['word'] . '</h1>';
   echo '<p>' . $_POST['sentence'] . '</p>';
  echo 'Invalid request';

How can I get the echo displayed in a CSS box or Javascript popup window.
Any help appreciated.

Hello, for a javascript popup window you just do this

echo "<script type='text/javascript'>alert('<h1>'". $_POST['word']."'</h1>')</script>";
Member Avatar

Any php-derived html/text can be placed anywhere in your page (js, styling, html element). However, php is not interactive like js, so if you want interactivity, e,g, drawing data from the server as the user interacts with the page, you will need to use Ajax.

In a simple case, store the text you want to display in a (string) variable:

if(isset($_POST['word']) && isset($_POST['sentence']) && trim($_POST['word']) && trim($_POST['sentence']))
    $string  = "<h1>{$_POST['word']}</h1>\n<p>{$_POST['sentence']}</p>";
    $string = '<p>Invalid request</p>';

Then where you need to place it...

<div class="myPopUp">
    <?php echo $string;?>

If this is an all in one page you may find that you get "Invalid Request" on page load before the form has been posted. In which case the code needs to be modified a little.