I’m a complete newbie when it comes to HTML, I’ve never needed to do any webpage stuff before so apologies if I’m being a simpleton.
I have a high score table for an iOS app, and I want to display it on the website for the app as well. The leaderboard is working fine in the app using PHP and mySQL, but when I try to access the database using PHP inside an HTML file it doesn’t seem to pay any attention to the logic of the PHP (i.e. if I have an if/else statement, it will run both even cases).
Here is a simplified version of my code, if connection to the database is successful then the first column in the table header will say “success”, otherwise it will say “failure”.
<body>
<table class="altrowstable" id="alternatecolor">
<?php
if (!mysql_connect($db_host, $db_user, $db_pwd))
{
<tr>
<th>Failure</th><th>Player</th><th>Points</th><th>Played</th><th>Wins</th><th>Draws</th><th>Losses</th>
</tr>
}
else
{
<tr>
<th>Success</th><th>Player</th><th>Points</th><th>Played</th><th>Wins</th><th>Draws</th><th>Losses</th>
</tr>
}
?>
</table>
</body>
Can anyone see what has been done incorrectly here? I assumed that the if/else would work as normal, but instead I get both rows inserted into the table, “failure” and “success”.
Edit:
I have also tried using echo “”; etc, but not sure which way is correct as they both give me the same error where it ignores the PHP.
Check extension of your file. It need to be filename.php
You need a server to launch php code
You can use echo heredoc like here
That seems to be working