1
echo '<a href="url_to_delete" onclick="return confirm('Are you sure want to delete') ;">Delete</a>';

i am having problem on the single quote. Parse error: syntax error, unexpected 'Are' (T_STRING), expecting ',' or ';' i tried change with

echo '<a href="url_to_delete" onclick="return confirm('.'Are you sure want to delete'.') ;">Delete</a>';

but the confimation pop out is not working. i need to use on single quote but not on double quote for php.

user2745422
  • 29
  • 2
  • 2
  • 6
  • You need to have quotes *for* PHPs strings. But also provide quotes valid *in* HTML *and* Javascript context. You can have PHP output some single quotes through escaping. Or use HTML entities. – mario Jan 03 '14 at 01:07
  • i tried used the suggested method Reference - What does this error mean in PHP? but it doesn't function correctly. The pop out confimation box is not come out. – user2745422 Jan 03 '14 at 01:10

2 Answers2

3

You need to escape the single quotes with a backslash:

echo '<a href="url_to_delete" onclick="return confirm(\'Are you sure want to delete\') ;">Delete</a>';
ryanbrill
  • 1,981
  • 10
  • 13
0

One of your problems is that you're not escaping your quotes in your string.

echo '<a href="url_to_delete" onclick="return confirm(\'Are you sure want to delete\') ;">Delete</a>';

The other one is you're echoing out plain html, you can exit php mode and simply output html

...
?>
<a href="url_to_delete" onclick="return confirm('Are you sure want to delete') ;">Delete</a>
<?php
...
Musa
  • 96,336
  • 17
  • 118
  • 137