jl1126
jl1126

Reputation: 21

How to put html href button inside php code

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>";

?>

Upvotes: 0

Views: 1505

Answers (1)

Fran&#231;ois Hupp&#233;
Fran&#231;ois Hupp&#233;

Reputation: 2116

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.

Upvotes: 1

Related Questions