Jump to content

A POST ERROR (please help)


paulman888888

Recommended Posts

My code is this

<?php
$filename = "games/{$_POST["name"]}.php";

if (file_exists($filename)) {
    echo "<p>Theres an error, the name of your game already exists.<br />Go back and change the name of the game.<br /><a href='javascript: history.go(-1)'>Or Click Here</a></p>";
} else {
    $ourFileName = "games/{$_POST["name"]}.php";
$ourFileHandle = fopen($ourFileName, 'w') or die("Can't make file");
fclose($ourFileHandle);

$myFile = "games/{$_POST["name"]}.php";
$fh = fopen($myFile, 'w') or die("There's an error!");
$stringData = "{$_POST["main"]}";
fwrite($fh, $stringData);
fclose($fh);
echo "GAME CREATED SUSCESS FULL";
}
?>

the create file part works but the stringData part doesn't I don't know why the StringData isn't adding the post data information

 

the post data is something like this

<i>This is an example and i hope it helps</i>

 

Please help me fix the post data.

 

thankyou

Link to comment
https://forums.phpfreaks.com/topic/106529-a-post-error-please-help/
Share on other sites

<?php
$data = $_POST['main'];
$name = $_POST['name'];

if(!$data || !$name){
echo "You need data and/or a name!";
}else {
$file = "/games/" . $name . ".php";

if(file_exists($file)){
	echo "The file <b>".$file."</b> already exists!\n";
}else {
	$f = fopen($file, "w+");
	fwrite($f, $data);
	fclose($f);

	echo "The game file has been created!\n";
}
}
?>

<?php
$filename = "games/{$_POST["name"]}.php";

if (file_exists($filename)) {
    echo "<p>Theres an error, the name of your game already exists.<br />Go back and change the name of the game.<br /><a href='javascript: history.go(-1)'>Or Click Here</a></p>";
} else {
    $ourFileName = "games/{$_POST["name"]}.php";
$ourFileHandle = fopen($ourFileName, 'w') or die("Can't make file");
fclose($ourFileHandle);
$myFile = $filename;
$fh = fopen($myFile, 'w+') or die("There's an error!");
$stringData = $_POST["main"];
fwrite($fh, $stringData);
fclose($fh);
echo "GAME CREATED SUSCESS FULL";
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.