I am able to take a name from a form a user has submitted and create a file using fopen. What I need to do is whenever a user hits that submit button I want to take their name $_POST['name']
and use it to rename a current file I have in the same directory. The files name is comment.PHP. and it has a script for entering comments. So ....when the user hits submit I need to to create a file with $_POST['name']
. So it should look like Jamescommet.PHP and if another person submites their name it will make a fill called tomcomment.php. and I need the files to keep the current script in it. So what should I change?
$filename = $_POST['name']_comment.PHP;
Thanks for the help, the only problem that persists. Is that none of the code from comment.PHP was included into the file created?
Thanks for the help, the only problem that persists. Is that none of the code from comment.PHP was included into the file created?
You need to enlcose some of this in quotes (or single quotes):
$filename = $_POST['name'] . "_comment.php";
In PHP the '.' is the concatenation operator. This means that it combines two strings into one. The quotes are used to encapsulate a string.
So to combine a variable like $_POST['name']
to a string such as _comment.php
we do the following: $_POST['name'] . "_comment.php"
This will combine the variable and the string like you expected.