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
Share on other sites

you should echo out $filename in various places and see what it is.

 

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

 

should be

 

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

 

you can't use unescaped double-quotes in a double-quoted string, so use single-quotes instead.

Link to comment
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";
}
}
?>

Link to comment
Share on other sites

<?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";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.