2

I'm trying to redirect to a specific page once an if condition is satisfied. The php also needs to send out an alert at the same time. I'm very new to all of this so correct me if I'm wrong, but to send out an alert and also redirect, javascript must be used because PHP can't do both. So I've got a couple of php variables that need to be accessed by the script. I think the problem is there but I'm not sure.

echo "<SCRIPT type='text/javascript'>
    alert('$message');
    window.location.replace(\"http://www.adidas.co.uk/on/demandware.store/Sites-adidas-GB-Site/en_GB/Cart-MiniAddProduct?pid="+"<?php echo $style ?>" + "_"+"<?php echo $size8 ?>"+"&masterPid="+"<?php echo $style ?>"\");
    </SCRIPT>";

I keep getting a parsing error. 'parse error, expecting','' or ';'' is the error.

Thanks in advance

bsaid97
  • 69
  • 2
  • 9

2 Answers2

3

Try this in php:

$style = "someStyle";
$myJS = <<<EOT
<script type='text/javascript'>
    window.location.replace("http://www.adidas.co.uk/on/demandware.store/Sites-adidas-GB-Site/en_GB/Cart-MiniAddProduct?pid=$style");
</script>
EOT;

echo($myJS);

I know this is just a portion of the url, but I'm just trying to give you the concept. Notice how I put $style into this multi-line string.

Lonnie Best
  • 9,936
  • 10
  • 57
  • 97
2

I think this will do it:

echo '<script type="text/javascript">
alert(\'' . $message . '\');
window.location.replace(\'http://www.adidas.co.uk/on/demandware.store/Sites-adidas-GB-Site/en_GB/Cart-MiniAddProduct?pid=' . $style . '_' . $size8 . '&masterPid=' . $style . '\')</script>';
raphael75
  • 2,982
  • 4
  • 29
  • 44