Huijari Posted August 5, 2009 Share Posted August 5, 2009 Hello can someone tell what is wrong with my code, it should make $player , $highscore in highscore.txt file... <?php //high score file name $scorefile='highscore.txt'; // number used same as in encryptor.swf $n1=1987; $n2=7; $n3=15; $n4=3; // $validation=$_POST['validation']; $highscore=$_POST['highscore']; $player=$_POST['player']; // encrypt the score the same way as in encryptor.swf $val=round(($highscore*$n4-$n3)/$n2+$n1); $output .= $scorelist[$i]['player'] . ',' . $scorelist[$i]['score'] . "\n"; // check whether the validation value is correct or not if($validation==$val){ echo '&valid=1&'; }else{ echo '&valid=0&'; return; } // if the validation value is correct, fetch the score list and insert it $fh=fopen($scorefile, 'w'); fwrite($fh,"$player,$highscore\n"); fclose($fh); }else{ echo '&valid=0&'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/168986-solved-post-data-from-php-to-txt-file/ Share on other sites More sharing options...
mikesta707 Posted August 5, 2009 Share Posted August 5, 2009 what exactly happens when you run this? is the .txt file not overwritten? does the file become empty? does the file not even open? Quote Link to comment https://forums.phpfreaks.com/topic/168986-solved-post-data-from-php-to-txt-file/#findComment-891600 Share on other sites More sharing options...
Huijari Posted August 5, 2009 Author Share Posted August 5, 2009 There happens nothing to the highscore.txt file. I don't know does it open.. how could I? Please help, and tell if you see anything wrong in my code... Quote Link to comment https://forums.phpfreaks.com/topic/168986-solved-post-data-from-php-to-txt-file/#findComment-891681 Share on other sites More sharing options...
machiavelli1079 Posted August 5, 2009 Share Posted August 5, 2009 did you try openeing in append mode? $fh=fopen($scorefile,'a'); does the file exist? after you execute the script you should be able to see the highscores.txt file in the same directory that the script is called from. Quote Link to comment https://forums.phpfreaks.com/topic/168986-solved-post-data-from-php-to-txt-file/#findComment-891743 Share on other sites More sharing options...
Huijari Posted August 6, 2009 Author Share Posted August 6, 2009 Woohoo! I fixed it myself! That php file didn't work, and problem was not in php... Thank you guys, Quote Link to comment https://forums.phpfreaks.com/topic/168986-solved-post-data-from-php-to-txt-file/#findComment-892407 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.