-1

I have the below section of code where I want to display how many orders have been added if conditions of the $orderstat are met. The alert works but not with the $orderstat variable inside it. Can anyone see what I am doing wrong? Thanks in advance!

    session_start();
$orderstat = $_SESSION['orderstat']; 
if ( $orderstat == "1" || $orderstat == "2" || $orderstat == "3" || $orderstat == "4") {
echo '<script language="javascript">';
**echo 'alert('<?php echo $orderstat; ?>' + "order/s successfully added to Job")';**
echo '</script>';
}
session_destroy();
J M
  • 37
  • 7
  • 1
    You need to learn basic PHP string syntax: http://php.net/manual/en/language.types.string.php, then take a VERY close look at your echo/alert line. – Marc B Jan 29 '15 at 14:35
  • Though in this case the problem isn't the PHP, it's the javascript. However, this is EASILY diagnosed yourself if you use a simple debugger. See here: http://stackoverflow.com/questions/988363/how-can-i-debug-my-javascript-code – Mark Jan 29 '15 at 14:35

2 Answers2

1

Change this line echo 'alert('<?php echo $orderstat; ?>' + "order/s successfully added to Job")';

to

echo 'alert("'.$orderstat.' order/s successfully added to Job")';

You are nesting the php again and again in line echo 'alert('' + "order/s successfully added to Job")';

user3535945
  • 241
  • 1
  • 10
-1
    session_start();
    $orderstat = $_SESSION['orderstat']; 
    if ( $orderstat == "1" || $orderstat == "2" || $orderstat == "3" || $orderstat == "4") {
    ?>
    <script language="javascript">
    alert("<?php echo $orderstat; ?> order/s successfully added to Job");
    </script>
    <?php
    }
    session_destroy();

Here, I have made correction. Instead of echo we can right code in this way. This is working code. Please check.

Domain
  • 11,562
  • 3
  • 23
  • 44