I came up with this php script to get 3 fields from an HTML form. I want the text field "name" to be the name of the txt file to write to. Here is my code:
<?php
$name = @$_POST["name"];
$file = "$name" . ".txt";
$v1 = @$_POST["v1"];
$v2 = @$_POST["v2"];
// Set the string to be written to the file
$values = "&v1=$v1\r\n";
$values .= "&v2=$v2\r\n";
// Open the file for truncated writing
$fp = @fopen($file, "w") or die("Couldn't open $file for writing!");
$numBytes = @fwrite($fp, $values) or die("Couldn't write values to file!");
@fclose($fp);
echo "Wrote $numBytes bytes to $file successfully!";
?>
$file is the name of the file. So if $name is aaron, it will write to aaron.txt, but my code is wrong, and I don't know how to fix it (I'm very new to php). Can anyone help?