There are several quotes that are not escaped and even if you do escape the double quotes that currently lead to your error, the rendered HTML markup will still have errors as you are using single quotes for attributes and JavaScript strings inside them. That way your JS will probably not work too. Example:
<button onclick='window.location.href='resources.php?subj=%s''>…</button>
In fact your code is a good example why one should avoid using variables inside a string. Each time I need to use a double quote in PHP I get the feeling that I did something wrong. Maybe a template engine is useful for you. The simplest version would be to use sprintf
to output that kind of strings:
$template = <<<EOTEMPLATE
<p style="color: orange; font-size: 25px;">%s -
<button type="button" onclick="window.location.href=\'resources.php?subj=%s\'" class="btn btn-sm btn-success pull-right">Resources</button>
<button onclick="window.location.href='questions.php?subj=%s'" class="btn btn-sm btn-success pull-right">Questions</button>
<button onclick="window.location.href='assessment.php?topic=%s'" class="btn btn-sm btn-success pull-right">Assessment</button>
</p>
<hr/>
EOTEMPLATE;
echo sprintf( $template, $result['Topic'], $result['Subject'], $result['Subject'], $result['Topic'] );
The next optimization iteration would be to remove those inline JS snippets and paste them in a single JS block (or even better: a separate *.js file). But as you are only loading another page, a simple link would do as well. The following snippet also should do what your input suggests. (As a link could also be styled to look like a button.)
$template = <<<EOTEMPLATE
<p class="btn-group">%s –
<a href="resources.php?subj=%s" class="btn btn-sm btn-success pull-right">Resources</a>
<a href="questions.php?subj=%s" class="btn btn-sm btn-success pull-right">Questions</a>
<a href="assessment.php?topic=%s" class="btn btn-sm btn-success pull-right">Assessment</a>
</p>
<hr/>
EOTEMPLATE;
echo sprintf( $template, $result['Topic'], $result['Subject'], $result['Subject'], $result['Topic'] );
Then, if you still need JavaScript (for example to implement a click tracker for those buttons) you can add an event handler to do so:
<script>
// add an event listener to the document object to capture clicks on existing and future links
document.addEventListener( 'click', function( event ) {
if( event.target.tagName === 'A' && event.target.classList.has( 'btn-success' ) ) {
event.preventDefault();
// do whatever you need to do with that link
window.location.href = event.target.href;
}
}, false );
</script>
(This JS example will only work in modern browsers because of the usage of "classList")