0

I am using this code in my controller and it's not working, showing parse error. Can you guys please help me out.

 echo "<script>
        alert("<?php echo $v[$keys[$i+4]],"is going out of stock"; ?>");
</script>" ;

Thank you!

5
  • include your error message.$v[$keys[$i+4]],"is going out of stock" should be $v[$keys[$i+4]]."is going out of stock" dot not comma Commented Jul 8, 2015 at 20:43
  • don't use alert it locks the browser, use a modal overlay or other form of notification like a growl Commented Jul 8, 2015 at 20:45
  • i've tried, but it's not working. It is showing parse error Commented Jul 8, 2015 at 20:47
  • Try to avoid spaghetti code, separe in different layers javascript from controller, you should at least put it inside some view, never in the controller, it brokes the mvc pattern Commented Jul 8, 2015 at 20:57
  • thanks @cmorrissey n #Balder for suggestion :) Commented Jul 8, 2015 at 21:00

1 Answer 1

1

You're not concatenating the static text correctly. Try this:

echo "<script>
    alert('" . $v[$keys[$i+4]] . " is going out of stock.');
</script>" ;
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Daniel . It has run successfully :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.