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 Link to comment https://forums.phpfreaks.com/topic/106529-a-post-error-please-help/ Share on other sites More sharing options...
BlueSkyIS Posted May 20, 2008 Share Posted May 20, 2008 $stringData = $_POST["main"]; Link to comment https://forums.phpfreaks.com/topic/106529-a-post-error-please-help/#findComment-546073 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. Link to comment https://forums.phpfreaks.com/topic/106529-a-post-error-please-help/#findComment-546078 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. Link to comment https://forums.phpfreaks.com/topic/106529-a-post-error-please-help/#findComment-546079 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"; } } ?> Link to comment https://forums.phpfreaks.com/topic/106529-a-post-error-please-help/#findComment-546080 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"; } ?> Link to comment https://forums.phpfreaks.com/topic/106529-a-post-error-please-help/#findComment-546084 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.