I have an html form (form.html) that asks for a name and surname (for example), once filled out and sent, it goes through a php file (data.php) that collects the data and stores it in different variables.
The thing is that I don't know how to do it, so that once it collects the data, the php file, it creates a new html document with that data automatically.
In data.php you take the variables of the form (I assume it is a POST) and create the file with the html content you want:
If you need to create a different file each time the form is submitted, you can either use the person's first and last name and add it to the filename itself (although it would be a good idea to clean this data of special characters and the like), or you can add a number verify that filenames exist, among other options.
Taking into account that you already process the content of the variables of the data.php file, you would only have to add a couple of lines to create a file and save its content.