Entire post disappears due to single line within script

              foreach ($dbPostList as $posts) {
                        echo '
                        	<table class="post">
                            	<tr><td class="userdetails">
                                	<a href="/viewprofile.php?id=' . $posts["memberId"] .'" class="username">' . $posts["memberUsername"] . '</a><br />
                                    <span class="postCount">Posts: ' . $posts["memberPostCount"] . '</a>
                                    >' . ($_SESSION["rank"] >= 2) ? '<a href="/__sys/admin.removePost.php?id=' . $posts["postId"] . '">[Remove Post]</a><br />' : "<br />";
                                    var_dump($posts) . '
                            	</td>
                            	<td class="postdetails">
                                	' . base64_decode($posts["postContent"]) . '
                            	</td></tr>
                            </table>
                        ';
                    }

Shows correct [Remove Post] link and var_dump($posts).
But everything else is gone. If I remove line:
>' . ($_SESSION["rank"] >= 2) ? '<a href="/__sys/admin.removePost.php?id=' . $posts["postId"] . '">[Remove Post]</a><br />' : "<br />"; and fix symantic errors, the table.post shows normally. But with this line there, post just disappears.

What do you get if you do a var_dump on $_SESSION[‘rank’] ? Is what you get what you expect to get?

You are terminating the statement (note the semi-colon).

($_SESSION["rank"] >= 2) ? '<a href="/__sys/admin.removePost.php?id=' . $posts["postId"] . '">[Remove Post]</a><br />' : "<br />";

If you change it to

                        echo '
                        	<table class="post">
                            	<tr><td class="userdetails">
                                	<a href="/viewprofile.php?id=' . $posts["memberId"] .'" class="username">' . $posts["memberUsername"] . '</a><br />
                                    <span class="postCount">Posts: ' . $posts["memberPostCount"] . '</a>
                                    >' . (($_SESSION["rank"] >= 2) ? '<a href="/__sys/admin.removePost.php?id=' . $posts["postId"] . '">[Remove Post]</a><br />' : "<br />") . '
                            	</td>
                            	<td class="postdetails">
                                	' . base64_decode($posts["postContent"]) . '
                            	</td></tr>
                            </table>
                        ';

I believe it will work. Worst case, move that ternary statement outside of your echo and store the link/empty br tag into a variable and reference that variable in the echo statement.

1 Like

string(1) "3", as expected and wanted.

Yep, pretty much the solution. Thank you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.