Cannot get PHP to output JS code correctly

I thought this would be a handy shortcut for the thing. However, the PHP appears to be breaking somehow. I’m thinking it might be the backslashes and apostrophes, but I’m not certain.

I had the code in a larger file, but cut out the part that seemed to be the problem area and put it in its own file. It doesn’t run at all and I don’t know how to get Chrome or whatever to show me any error messages that I can understand.

[php]

<?php $articles2 = array("I. Of the Scriptures", "II. Of the True God", "III. Of the Holy Spirit", "IV. Of the Devil, Or Satan", "V. Of the Creation", "VI. Of the Fall of Man", "VII. Of the Virgin Birth", "VIII. Of the Atonement for Sin", "IX. Of Grace in the New Creation", "X. Of the Freeness of Salvation", "XI. Of Justification", "XII. Of Repentance and Faith", "XIII. Of the Church", "XIV. Of Baptism and the Lords Supper", "XV. Of the Perseverance of the Saints", "XVI. Of the Righteous and the Wicked", "XVII. Of Civil Government", "XVIII. Of the Resurrection and Return of Christ and Related Events", "XIX. Of Missions", "XX. Of the Grace of Giving", "Closing"); $articleSize = count($articles2); for ($x =0; $x < $articleSize; $x++) { echo "". $articles2[$x] . ""; echo ""; echo "
"; } ?> [/php]

So, what is the error?

Change your button tag to something like

echo "<button class=\"button\" onclick=\"location.href='./articlesOfFaith.php?article=' + " . $x + 1 . "'>" . $articles2[$x] . "</button>";

And leave out the tags.

It’s now showing something like:

1’>I. Of the Scriptures
1’>II. Of the True God
1’>III. Of the Holy Spirit
1’>IV. Of the Devil, Or Satan
1’>V. Of the Creation
1’>VI. Of the Fall of Man
1’>VII. Of the Virgin Birth
1’>VIII. Of the Atonement for Sin
1’>IX. Of Grace in the New Creation
1’>X. Of the Freeness of Salvation
1’>XI. Of Justification
1’>XII. Of Repentance and Faith
1’>XIII. Of the Church
1’>XIV. Of Baptism and the Lord’s Supper
1’>XV. Of the Perseverance of the Saints
1’>XVI. Of the Righteous and the Wicked
1’>XVII. Of Civil Government
1’>XVIII. Of the Resurrection and Return of Christ and Related Events
1’>XIX. Of Missions
1’>XX. Of the Grace of Giving
1’>Closing

It’s not even making the buttons. It is showing something though, which is better than it was before, when it just plan didn’t do anything.

—UPDATE-----

I edited it some and now it’s making buttons, but they’re not redirecting because I’m not sure how to handle the break between JS and PHP after “article?=”

Here is the code now:
[php]

Shooting Park Road Baptist Church .button { //padding: 15px 25px; padding: 6px 9px; font-size: 12px; text-align: center; cursor: pointer; outline: none; color: #0000aa; background-color: #DDEEDD; border: none; border-radius: 15px; box-shadow: 0 9px #999; } body { background-image: url("./clouds.jpg"); background-size: cover; } .button:hover {background: cyan;} .button:active { background-color: #3e8e41; box-shadow: 0 5px #666; transform: translateY(4px); } <?php $articles2 = array("I. Of the Scriptures", "II. Of the True God", "III. Of the Holy Spirit", "IV. Of the Devil, Or Satan", "V. Of the Creation", "VI. Of the Fall of Man", "VII. Of the Virgin Birth", "VIII. Of the Atonement for Sin", "IX. Of Grace in the New Creation", "X. Of the Freeness of Salvation", "XI. Of Justification", "XII. Of Repentance and Faith", "XIII. Of the Church", "XIV. Of Baptism and the Lord's Supper", "XV. Of the Perseverance of the Saints", "XVI. Of the Righteous and the Wicked", "XVII. Of Civil Government", "XVIII. Of the Resurrection and Return of Christ and Related Events", "XIX. Of Missions", "XX. Of the Grace of Giving", "Closing"); $articleSize = count($articles2); for ($x =0; $x < $articleSize; $x++) { ?>

<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +

<?php echo $x + 1 . "'>" . $articles2[$x] ; ?> <?php echo "
"; } ?> [/php]

And this is what it looks like now:

Shooting Park Road Baptist Church .button { //padding: 15px 25px; padding: 6px 9px; font-size: 12px; text-align: center; cursor: pointer; outline: none; color: #0000aa; background-color: #DDEEDD; border: none; border-radius: 15px; box-shadow: 0 9px #999; } body { background-image: url("./clouds.jpg"); background-size: cover; } .button:hover {background: cyan;} .button:active { background-color: #3e8e41; box-shadow: 0 5px #666; transform: translateY(4px); }

<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
1’>I. Of the Scriptures


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
2’>II. Of the True God


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
3’>III. Of the Holy Spirit


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
4’>IV. Of the Devil, Or Satan


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
5’>V. Of the Creation


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
6’>VI. Of the Fall of Man


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
7’>VII. Of the Virgin Birth


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
8’>VIII. Of the Atonement for Sin


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
9’>IX. Of Grace in the New Creation


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
10’>X. Of the Freeness of Salvation


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
11’>XI. Of Justification


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
12’>XII. Of Repentance and Faith


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
13’>XIII. Of the Church


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
14’>XIV. Of Baptism and the Lord’s Supper


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
15’>XV. Of the Perseverance of the Saints


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
16’>XVI. Of the Righteous and the Wicked


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
17’>XVII. Of Civil Government


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
18’>XVIII. Of the Resurrection and Return of Christ and Related Events


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
19’>XIX. Of Missions


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
20’>XX. Of the Grace of Giving


<button class=“button” onclick= “location.href=’./articlesOfFaith.php?article=” +
21’>Closing


Got it to work. I had to put a lot outside the PHP code:

[php]

Shooting Park Road Baptist Church .button { //padding: 15px 25px; padding: 6px 9px; font-size: 12px; text-align: center; cursor: pointer; outline: none; color: #0000aa; background-color: #DDEEDD; border: none; border-radius: 15px; box-shadow: 0 9px #999; } body { background-image: url("./clouds.jpg"); background-size: cover; } .button:hover {background: cyan;} .button:active { background-color: #3e8e41; box-shadow: 0 5px #666; transform: translateY(4px); } <?php $articles2 = array("I. Of the Scriptures", "II. Of the True God", "III. Of the Holy Spirit", "IV. Of the Devil, Or Satan", "V. Of the Creation", "VI. Of the Fall of Man", "VII. Of the Virgin Birth", "VIII. Of the Atonement for Sin", "IX. Of Grace in the New Creation", "X. Of the Freeness of Salvation", "XI. Of Justification", "XII. Of Repentance and Faith", "XIII. Of the Church", "XIV. Of Baptism and the Lord's Supper", "XV. Of the Perseverance of the Saints", "XVI. Of the Righteous and the Wicked", "XVII. Of Civil Government", "XVIII. Of the Resurrection and Return of Christ and Related Events", "XIX. Of Missions", "XX. Of the Grace of Giving", "Closing"); $articleSize = count($articles2); for ($x =0; $x < $articleSize; $x++) { ?> <?php echo $articles2[$x] ; ?> <?php echo "
"; } ?> [/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service