0

I'm trying to put an html href button inside of my php code, but when I run it, I get an error message saying "This Page Isn't Working."

<?php

echo "<button onclick="location.href='phpfile.php';">My Button</button>";

?>
1
  • try window.location Commented Jul 21, 2019 at 11:01

1 Answer 1

1

Either you need to escape the HTML double quotes:

echo "<button onclick=\"location.href='phpfile.php';\">My Button</button>";

Or the Javascript single quotes:

echo '<button onclick="location.href=\'phpfile.php\';">My Button</button>';

By the way,

This Page Isn't Working.

Means a 500 error, which means your php script does not compile. Most of the time it is due to syntax errors.

Sign up to request clarification or add additional context in comments.

Comments

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.