coollog Posted November 27, 2008 Share Posted November 27, 2008 My MySQL server site is down so I couldn't make a highscores database in MySQL, which would be a lot easier. I am not that good at PHP since I just started learning the day before yesterday so just please help me. I've been trying to create a PHP highscores database w/o the use of MySQL. It currently has 3 scripts to it, a create.php with parameters data and pass, a add.php with parameters data, pass, name, and score, and a display.php with parameter data. I have some trouble displaying the scores in a list from .dat files you create. It used to work. I also have some trouble adding new names tagged with their scores. Please help! Below are the 3 scripts: display.php <html> <body> <?php if (!isset($_REQUEST["data"])) exit("Invalid highscores data name!"); if (file_exists($_REQUEST["data"].".dat")) $file = fopen($_REQUEST["data"].".dat","r") or exit("Unable to load highscores!"); else exit("Highscores data doesn't exist!"); if (file_exists($_REQUEST["data"].".dat2")) $file2 = fopen($_REQUEST["data"].".dat2","r") or exit("Unable to load highscores!"); else exit("Highscores data doesn't exist!"); $place=0; $pss=fgets($file); echo $pss; while((!feof($file)) && (!feof($file2))) { $place++; $name=fgets($file); echo $name; $score=fgets($file2); echo $score; if(($score!="") and ($name!="")) echo $place."-".$name." ".$score."<br>"; } fclose($file); fclose($file2); ?> </body> </html> create.php (This works fine) <html> <body> <?php if (!isset($_REQUEST["data"])) exit("Invalid highscores data name!"); if (!isset($_REQUEST["pass"])) exit("Invalid highscores data password!"); if (!file_exists($_REQUEST["data"].".dat")) $file=fopen($_REQUEST["data"].".dat","x") or exit("Unable to create highscores data!"); else exit("Highscores data already exists!"); if (!file_exists($_REQUEST["data"].".dat2")) $file2=fopen($_REQUEST["data"].".dat2","x") or exit("Unable to create highscores data!"); else exit("Highscores data already exists!"); fwrite($file,$_REQUEST["pass"]); fclose($file); fclose($file2); echo "Highscores data with name, ".$_REQUEST["data"].", and password, ".$_REQUEST["pass"].", created successfully!" ?> </body> </html> add.php <html> <body> <?php if (!isset($_REQUEST["data"])) exit("Invalid highscores data name!"); if (!isset($_REQUEST["pass"])) exit("Invalid highscores data password!"); if (!isset($_REQUEST["name"])) exit("Invalid entry name!"); if (!isset($_REQUEST["score"])) exit("Invalid entry score!"); if (file_exists($_REQUEST["data"].".dat")) $file = fopen($_REQUEST["data"].".dat","r") or exit("Unable to load highscores!"); else exit("Highscores data doesn't exist!"); if (file_exists($_REQUEST["data"].".dat2")) $file2 = fopen($_REQUEST["data"].".dat2","r") or exit("Unable to load highscores!"); else exit("Highscores data doesn't exist!"); if($_REQUEST["pass"]!=fgets($file)) { fclose($file); fclose($file2); exit("Incorrect password for highscores data, ".$_REQUEST["data"]."!"); } $place=0; while((!feof($file)) && (!feof($file2))) { $place++; $scr=fgets($file2); if($scr<$_REQUEST["score"]) break; } fclose($file); fclose($file2); $file = fopen($_REQUEST["data"].".dat","r+"); $file2 = fopen($_REQUEST["data"].".dat2","r+"); $read = file($_REQUEST["data"].".dat"); $read["Set"]=$_REQUEST["name"]; fwrite($file,$read[0]." "); for($s=1;$s<place;$s++) { fwrite($file,$read[$s+1]); } fwrite($file,$read["Set"]." "); for($s=place+1;$s<=count($read)-1;$s++) { fwrite($file,$read[$s+1]); } fclose($file); $read = file($_REQUEST["data"].".dat2"); $read["Set"]=$_REQUEST["score"]; for($s=0;$s<place-1;$s++) { fwrite($file2,$read[$s]); } fwrite($file2,$read["Set"]." "); for($s=place;$s<=count($read)-2;$s++) { fwrite($file2,$read[$s]); } fclose($file2); include("display.php") ?> </body> </html> If you have any better way to make this, PLEASE tell me, thank you! Quote Link to comment https://forums.phpfreaks.com/topic/134448-php-highscorescan-you-solve-it/ Share on other sites More sharing options...
.josh Posted November 27, 2008 Share Posted November 27, 2008 your sql server is down so you opt to make a flatfile solution instead of fixing the server? Quote Link to comment https://forums.phpfreaks.com/topic/134448-php-highscorescan-you-solve-it/#findComment-699983 Share on other sites More sharing options...
coollog Posted November 27, 2008 Author Share Posted November 27, 2008 your sql server is down so you opt to make a flatfile solution instead of fixing the server? Yea, but I can't fix the server since I don't have access to it. It is down for maintenance. So, uhh, can you solve the bug? I've been trying to fix it for hours already... Quote Link to comment https://forums.phpfreaks.com/topic/134448-php-highscorescan-you-solve-it/#findComment-699987 Share on other sites More sharing options...
.josh Posted November 27, 2008 Share Posted November 27, 2008 So...you just started learning php 2 days ago, and yet managed to master it enough to come up with all that? And what about that "It used to work" statement? Since you just started php 2 days ago, did it used to work, what, yesterday? Quote Link to comment https://forums.phpfreaks.com/topic/134448-php-highscorescan-you-solve-it/#findComment-699992 Share on other sites More sharing options...
Maq Posted November 27, 2008 Share Posted November 27, 2008 So, uhh, can you solve the bug? Bug? This is a serious problem if it's been down for hours. Why don't you call your hosting provider and ask them what's going on. Downtime usually does not last this long... Quote Link to comment https://forums.phpfreaks.com/topic/134448-php-highscorescan-you-solve-it/#findComment-699993 Share on other sites More sharing options...
coollog Posted November 27, 2008 Author Share Posted November 27, 2008 So...you just started learning php 2 days ago, and yet managed to master it enough to come up with all that? And what about that "It used to work" statement? Since you just started php 2 days ago, did it used to work, what, yesterday? Like a couple hours ago, somehow, it was working, but that was b4 I created the other 2 scripts, then I edited it a little, and it went kaploosh... Plus, PHP isn't that hard, and I didn't master it, my creations don't work... EDIT: @Maq The bug is in the scripts, I've been using another server for executing my php files, so please, just help me fix the scripts. Quote Link to comment https://forums.phpfreaks.com/topic/134448-php-highscorescan-you-solve-it/#findComment-699998 Share on other sites More sharing options...
.josh Posted November 27, 2008 Share Posted November 27, 2008 so what did you change? Quote Link to comment https://forums.phpfreaks.com/topic/134448-php-highscorescan-you-solve-it/#findComment-700000 Share on other sites More sharing options...
coollog Posted November 27, 2008 Author Share Posted November 27, 2008 so what did you change? I can't quite remember, o yea, I added that fgets($file); after the $place=0 (the echo after it was for testing) since the first line has the password after I created the create.php. Quote Link to comment https://forums.phpfreaks.com/topic/134448-php-highscorescan-you-solve-it/#findComment-700002 Share on other sites More sharing options...
coollog Posted November 27, 2008 Author Share Posted November 27, 2008 The bug should be just calculations, not some hard bug, just you need good math. Quote Link to comment https://forums.phpfreaks.com/topic/134448-php-highscorescan-you-solve-it/#findComment-700611 Share on other sites More sharing options...
coollog Posted November 30, 2008 Author Share Posted November 30, 2008 Ok, I have another code that seems to not work, and somehow I can't find the edit topic post button, so ill post here: if (!file_exists($REQUEST["data"])) exit("Highscores table, ".$REQUEST["data"]." doesn't exist!") Please help me fix this, it says some error in the if part. Quote Link to comment https://forums.phpfreaks.com/topic/134448-php-highscorescan-you-solve-it/#findComment-701954 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.