-2

Im creating a new php site with this script. I try everything to get $_POST['name'] into the new generated PHP site.

$myFile = "art.php";    
$fh = fopen($myFile, 'w'); 
$stringData = "<span>" . echo $_POST['name']; . "</span>";


fwrite($fh, $stringData);
fclose($fh);

PHP always tells me that there is an parse error. When I delete the PHP code everything works as expected. I also tried:

$stringData = "<span>" . echo 'test' . "</span>"; 

So basically every php code I try to add doesn't work.

2 Answers2

3

Try this code:

$myFile = "art.php";    
$fh = fopen($myFile, 'w'); 
$name = isset($_POST['name']) ? $_POST['name'] : '';
$stringData = "<span>$name</span>";


fwrite($fh, $stringData);
fclose($fh);
Vasyl Zhuryk
  • 1,140
  • 7
  • 22
1

Change:

$stringData = "<span>" . echo $_POST['name']; . "</span>";

To:

$stringData = "<span>" . $_POST['name'] . "</span>";

Rushikumar
  • 1,698
  • 5
  • 17
  • 28