First, before we tackle anything else, let's fix that HTML output you are doing. For this, I'll write it using the HEREDOC syntax, as I think it will make it easier to see the mistakes, then I'll show you the corrected version.
PHP Code:
$posts <<< HTML
<tr>
<td>
<font color=white>$tourneyname</td>
</font>
<td>
<font color=white>$start</td>
</font>
<td>
<font color=white>$location</td>
</font>
<td>
<font color=white>$prize</td>
</font>
<a href=>
<td>
<font color=white>$brackets</td>
</font>
<td>
<font color=white>$signup</td>
</font>
<td>
<font color=white>$stream</td>
</font>
<td>
<font color=white>$forum</td>
</font>
</tr>
</a>
<tr>
<td>$posts</tr>
</td>
</table>
HTML;
Do you see the problems?
- Your closing </font> tags are in the wrong spot, they need to be inside the <td></td> tags.
- You really should have quotes around your "white" color value. HEREDOC syntax will help you with that
- You are opening a link around a <td>, that has no URL... and then it closes well after its usefulness
- The very end of the HTML is just strange to say the least, plus I'm not sure why you are closing the table, when you never opened one...
Okay, so the corrected version of your HTML (again in HEREDOC syntax)
PHP Code:
$updatedPosts <<< HTML
<tr>
<td>
<font color="white">$tourneyname</font>
</td>
<td>
<font color="white">$start</font>
</td>
<td>
<font color="white">$location</font>
</td>
<td>
<font color="white">$prize</font>
</td>
<td>
<font color="white">$brackets</font>
</td>
<td>
<font color="white">$signup</font>
</td>
<td>
<font color="white">$stream</font>
</td>
<td>
<font color="white">$forum</font>
</td>
</tr>
$posts
HTML;
Okay, now that the HTML is cleaned up, let's analyze why your file isn't containing both tournament entries. So let's take a look at your old code
PHP Code:
$posts = file_get_contents("posts.txt");
$posts = "<tr><td><font color=white>$tourneyname</td></font><td><font color=white>$start</td></font><td><font color=white>$location</td></font><td><font color=white>$prize</td></font><a href=><td><font color=white>$brackets</td></font><td><font color=white>$signup</td></font><td><font color=white>$stream</td></font><td><font color=white>$forum</td></font></tr></a>" . "<tr><td>$posts</tr></td></table>";
file_put_contents("posts.txt", $posts);
Actually, I'm not 100% certain why it wouldn't be storing both values. My guess is it might be, but due to the invalid HTML, you are not seeing both records. However, the following code should work
PHP Code:
<?php
$tourneyname = $_POST["tournamentname"];
$start = $_POST["start"];
$location = $_POST["location"];
$prize = $_POST["prize"];
$brackets = $_POST["brackets"];
$signup = $_POST["signup"];
$stream = $_POST["stream"];
$forum = $_POST["forum"];
$posts = file_get_contents("posts.txt");
$updatedPosts <<< HTML
<tr>
<td>
<font color="white">$tourneyname</font>
</td>
<td>
<font color="white">$start</font>
</td>
<td>
<font color="white">$location</font>
</td>
<td>
<font color="white">$prize</font>
</td>
<td>
<font color="white">$brackets</font>
</td>
<td>
<font color="white">$signup</font>
</td>
<td>
<font color="white">$stream</font>
</td>
<td>
<font color="white">$forum</font>
</td>
</tr>
$posts
HTML;
file_put_contents("posts.txt", $updatedPosts);
?>
Okay, before I give you the A-OK on this, I do want to point out 1 more thing. The use of file_get_contents() and file_put_contents is overkill in this scenario. As you will be constantly reading the entire file and writing the entire data back to file.
When the file gets REALLY REALLY large, you will have problems.
You can resolve this by using fopen, fwrite, and fclose as shown below:
PHP Code:
<?php
$tourneyname = $_POST["tournamentname"];
$start = $_POST["start"];
$location = $_POST["location"];
$prize = $_POST["prize"];
$brackets = $_POST["brackets"];
$signup = $_POST["signup"];
$stream = $_POST["stream"];
$forum = $_POST["forum"];
$updatedPosts <<< HTML
<tr>
<td>
<font color="white">$tourneyname</font>
</td>
<td>
<font color="white">$start</font>
</td>
<td>
<font color="white">$location</font>
</td>
<td>
<font color="white">$prize</font>
</td>
<td>
<font color="white">$brackets</font>
</td>
<td>
<font color="white">$signup</font>
</td>
<td>
<font color="white">$stream</font>
</td>
<td>
<font color="white">$forum</font>
</td>
</tr>
HTML;
$fileHandler = fopen("posts.txt", "c");
fwrite($fileHandler, $updatedPosts);
fclose($fileHandler);
?>
Okay, first thing I did was remove the file_get_contents() line
Next I removed the $posts variable from the HTML code (it was previously before the HTML; line)
Finally I replaced the file_put_contents() with the fopen, fwrite, and fclose code.
The "c" states to open the file for writing, if the file doesn't exist, create it, if it does exist, put the cursor on the first line (so anything you write, will be written above the existing content).
I'll have to get back to you on the validation bit, but if you start with these changes first, we can make our way to that process.
Bookmarks