adamriley Posted May 10, 2010 Share Posted May 10, 2010 taken.php <?php session_start(); $adam = $_SESSION['dir']; $pfile = fopen("Places/$adam.txt","r"); rewind($pfile); while (feof($pfile)) { $line = fgets($pfile); $tmp = explode(':', $line); $name = $tmp[0]; fclose($pfile); } ?> $_SESSION['dir'] = England England.txt Adam Riley:adam162@******.com:9846 I would hope that is echo's the "Adam Riley" bit of the file but it does not Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 I don't see an "echo" statement in your code snippet. Also, you might want to look at the fgetcsv function. Ken Quote Link to comment Share on other sites More sharing options...
adamriley Posted May 10, 2010 Author Share Posted May 10, 2010 The echo statement is in the html under the php if i use "error_reporting(E_ALL);" I get "Notice: Undefined variable: name in C:\xampp\htdocs\Game\Check\Taken.php on line 23" Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 Please post all of the code, so we can see what you see. Ken Quote Link to comment Share on other sites More sharing options...
adamriley Posted May 10, 2010 Author Share Posted May 10, 2010 <?php session_start(); $adam = $_SESSION['dir']; $pfile = fopen("Places/$adam.txt","r"); rewind($pfile); while (feof($pfile)) { $line = fgets($pfile); $tmp = explode(':', $line); $name = $tmp[0]; fclose($pfile); } error_reporting(E_ALL); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Foot Ball game card || Place Taken</title> </head> <body bgcolor="#FF0000" text="#000000"> <div id="Text2" style="position:absolute;left:31px;top:158px;width:698px;height:64px;z-index:0;" align="left"> <font style="font-size:27px" color="#FFFF00" face="Arial">This slot has already been taken by </font><font style="font-size:27px" color="#0000FF" face="Arial"><?php echo $name ?></font></div> <div id="Text1" style="position:absolute;left:34px;top:95px;width:660px;height:32px;z-index:1;" align="left"> <font style="font-size:27px" color="#FFFF00" face="Arial">You have selected </font><font style="font-size:27px" color="#0000FF" face="Arial"><?php echo $_SESSION['dir'] ?></font></div> <div id="Text3" style="position:absolute;left:280px;top:17px;width:305px;height:36px;z-index:2;" align="left"> <font style="font-size:32px" color="#FFFF00" face="Arial"><u>Football Game Card</u></font></div> <input type="submit" id="Button1" onclick="window.close();return false;" name="Button1" value="Close" style="position:absolute;left:211px;top:271px;width:339px;height:72px;font-family:Arial;font-size:19px;z-index:3"> </body> </html> Theres the full file Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 Move the "error_reporting(E_ALL);" line to the start of your script. There's probably another error that you're not seeing. Ken Quote Link to comment Share on other sites More sharing options...
adamriley Posted May 10, 2010 Author Share Posted May 10, 2010 it adds this <b>Notice</b>: A session had already been started - ignoring session_start() in <b>C:\xampp\htdocs\Game\Check\Taken.php</b> on line <b>3</b><br /> and thats it Quote Link to comment Share on other sites More sharing options...
ignace Posted May 10, 2010 Share Posted May 10, 2010 while (!feof($pfile)) note the ! Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 Good catch. That would do it, since the loop never gets executed and the variables never get set. Missed that completely, since I've been using file or file_get_contents for reading files. Ken Quote Link to comment Share on other sites More sharing options...
adamriley Posted May 10, 2010 Author Share Posted May 10, 2010 Changed it and now i get Notice: A session had already been started - ignoring session_start() in C:\xampp\htdocs\Game\Check\Taken.php on line 3 Warning: feof(): 7 is not a valid stream resource in C:\xampp\htdocs\Game\Check\Taken.php on line 8 Warning: fgets(): 7 is not a valid stream resource in C:\xampp\htdocs\Game\Check\Taken.php on line 9 Warning: fclose(): 7 is not a valid stream resource in C:\xampp\htdocs\Game\Check\Taken.php on line 12 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 You have the fclose() statement within your loop. Move it outside the reading loop. Also, I don't think you need the "rewind()" statement. Ken Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 I took your code and simplified it by using the file function to read the file: <?php error_reporting(E_ALL); session_start(); $adam = $_SESSION['dir']; $tmp = file("Places/$adam.txt"); list($name) = explode(':',$tmp[0]); ?> Ken 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.