paulman888888 Posted May 20, 2008 Share Posted May 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 20, 2008 Share Posted May 20, 2008 $stringData = $_POST["main"]; Quote Link to comment Share on other sites More sharing options...
paulman888888 Posted May 20, 2008 Author Share Posted May 20, 2008 it doesn't work! I tested it and the file size is 0. for some reason its not adding my data. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 20, 2008 Share Posted May 20, 2008 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. Quote Link to comment Share on other sites More sharing options...
marcus Posted May 20, 2008 Share Posted May 20, 2008 <?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"; } } ?> Quote Link to comment Share on other sites More sharing options...
jonsjava Posted May 20, 2008 Share Posted May 20, 2008 <?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"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.