Q:

Print with PHP into Javascript

Code for the analysis of the payment page but does not write the code in javascript codes..
For example (HTML Print):

<script>
woopra.track('Odeme Sayfasi', {
    urunSayisi: '',
    amount: '',
    currency: '$'
});
</script>
    21234.55

2: 2 pcs products
1234.55: amount
PHP & Javascript codes:
<?php 
$mageFilename = '/home4/emre2010/public_html/app/Mage.php';
require_once $mageFilename;
umask(0);
Mage::app();
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('checkout/session');
$output = "";
foreach ($session->getQuote()->getAllItems() as $item) { ?>

<script>
woopra.track('Payment Page', {
    urunSayisi: '<?php $output .= $item->getQty(); ?>',
    amount: '<?php $output .= $item->getBaseCalculationPrice(); ?>',
    currency: '$'
});
</script>

<?php } print $output;  ?>

Why not write into the javascript code? - Where I make mistake?
P.S: E-commerce script: Magento1

A:

You're mixing 2 approaches. When you close the PHP tags and start your JavaScript code, that's getting output directly into the page. Then you're storing information in a variable instead of outputting it directly into the content.
You need to do something like this:
<script>
woopra.track('Payment Page', {
  urunSayisi: '<?php echo $item->GetQty(); ?>',
  amount: '<?php echo $item->getBaseCalculationPrice(); ?>',
  currency: '$'
});
</script>

If you want to build your JavaScript code and spit it out all in one go, then you'd need to put your JS code into a PHP variable and then print the output, like so:
<?php
$output = '';
$output .= "<script>";
$output .= "  woopra.track('PaymentPage', {";
$output .= "    urunSayisi: '" . $item->GetQty() . "',";

etc.
But the top approach of printing directly into your code is simpler and cleaner for what you seem to be doing.

