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 Link to comment https://forums.phpfreaks.com/topic/201271-file-and-echo-help/ 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 Link to comment https://forums.phpfreaks.com/topic/201271-file-and-echo-help/#findComment-1055928 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" Link to comment https://forums.phpfreaks.com/topic/201271-file-and-echo-help/#findComment-1055946 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 Link to comment https://forums.phpfreaks.com/topic/201271-file-and-echo-help/#findComment-1055955 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 Link to comment https://forums.phpfreaks.com/topic/201271-file-and-echo-help/#findComment-1055966 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 Link to comment https://forums.phpfreaks.com/topic/201271-file-and-echo-help/#findComment-1055975 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 Link to comment https://forums.phpfreaks.com/topic/201271-file-and-echo-help/#findComment-1055986 Share on other sites More sharing options...
ignace Posted May 10, 2010 Share Posted May 10, 2010 while (!feof($pfile)) note the ! Link to comment https://forums.phpfreaks.com/topic/201271-file-and-echo-help/#findComment-1055991 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 Link to comment https://forums.phpfreaks.com/topic/201271-file-and-echo-help/#findComment-1055993 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 Link to comment https://forums.phpfreaks.com/topic/201271-file-and-echo-help/#findComment-1055996 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 Link to comment https://forums.phpfreaks.com/topic/201271-file-and-echo-help/#findComment-1056005 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 Link to comment https://forums.phpfreaks.com/topic/201271-file-and-echo-help/#findComment-1056008 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.