Hi i need to create a form in a .html file myteamform.html, then take the data entered into the form and process it in a .php file "roster.php" which takes the data and adds it another.html page team_roster.html. I have my form done, my problem is how do you add the data to the second .html page through the .php file. Right now i have my php writing the data to a file, but i can't read the data from the file unless my team_roster.html page is .php. Basically what i need help with is how to the form data through the .php file and output from another .html file.

Dani AI

Generated

Short answer: treat the roster as data-driven, not as a hand-edited static HTML page. That is the most robust, secure, and maintainable route. was pointing in the right direction when suggesting a persistent store; and highlighted server-side parsing and form methods, but turning the roster into a page that PHP generates from stored data avoids fragile file-per-write hacks.

Recommended flow (practical, server-friendly)

  • Have the form submit to your PHP handler. The handler validates and sanitizes every field, then records the submission in a data store (a database is best; a well-structured CSV or JSON file can work for tiny projects).
  • Create a single roster page that queries that data store and renders the roster on demand. This makes concurrency, searching, editing, and backups straightforward and keeps security controls in one place (use prepared statements if you use SQL).

If you must produce/append a static HTML fragment (not recommended), do it safely:

  • Ensure the web process actually has write permission to the target file (prefer changing owner/group to the webserver user rather than opening 0777).
  • Sanitize user input before embedding it into HTML to prevent XSS.
  • Use atomic writes or file locking to avoid race conditions when multiple users submit simultaneously; do not rely on ad hoc string concatenation without locking.

Example of a safe append pattern (new example):

<?php
$line = '<li>' . htmlspecialchars(trim($_POST['name']), ENT_QUOTES, 'UTF-8') . "</li>\n";
file_put_contents('team_roster.html', $line, FILE_APPEND | LOCK_EX);
?>

Final cautions: sanitize and validate all input server-side, avoid storing raw HTML from users, and test concurrent submissions. If the host restricts .htaccess tweaks (see ), the simplest, most portable fix is to serve the roster as a PHP-generated page.

Recommended Answers

All 3 Replies

1) you can't
2) You need to setup $_POST (or $_GET, depending on the method you use) variables to receive the form data, then have it connect/insert the data into a mysql database, and then put a while loop in your team_roster.php page that selects all the rows from the team table.

If any of this sounds confusing, consult www.w3schools.org and read up on PHP.

Member Avatar for Member #120589

You can alter your .htccess file to allow php within .html files.

Add this to it:

AddType application/x-httpd-php .html .htm

Alternatively, rename the html file to php

you can add data to another page of your html either by

$_POST['variab1e_value']

or

$_GET['varible_value']

method depending on your form.
e.g
oh your HTML code

<form action="form_action.asp" method="get">
  First name: <input type="text" name="fname" /><br />
  Last name: <input type="text" name="lname" /><br />
  <input type="submit" value="Submit" />
</form>

the method of the form here is GET, therefore your php code for get method is

<?php echo $_GET["fname"] ."<br />".$_GET["lname"]; ?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.