I am currently having problems writing data inputted to a form into a .txt file. I've looked a couple different places, all of which seem to provide the same code, and it just isn't working for me. In fact, it doesn't even seem to be touching the text file. Here's the code:
Your code is perfectly correct, the problem may lie in permission. Make sure that the folder you are creating/appending the file has the read/write permission. Just to check you can go through functions like is_readable,is_writeable.
I put the code at the top of the php statement and when I first opened the page, this is what I got:
Notice: Undefined index: Semester in C:\wamp\www\newland\sem_select.php on line 37
Notice: Undefined index: Year in C:\wamp\www\newland\sem_select.php on line 38
file readfile written
I'm assuming this means that the error code is working as I have the form on the same page and those variables aren't defined at first. After I submit the form, these errors go away and it still doesn't write to the text file.
I don't understand why it isn't writing to the file.
The first thing to check is whether there are any values in your variables. If there are not, of course it won't add anything to the file. You can check this by echoing the variables to the screen just before (or instead of) trying to write them to the file. You could also try to write a defined string to the file. If it writes "hello" okay but won't write your variables, then you know that your problem is not in your syntax or permissions, but in your variables. If it won't write "hello" to the file, then you know that your problem must be file permissions or something like that. Always try to narrow down the area that is causing the problem, by eliminating possibilities.
I have actually tried to echo the values in the variables and they echo what the form submits properly. I also tried just writing static text ("hello") into the file and it didn't write it properly. As you said, this means it must have something to do with permissions. When I go to the file in Windows Explorer and go to its properties, "Read Only" is unchecked. However, when I got up one level in the folder structure, the folder that contains the text file is read only; as is the folder above that one, and the one above that. When I try to uncheck the read only checkbox, it seems to work as it goes through a sequence, as if to say that it is working. When i close the properties dialog and reopen it, read only is checked again. Is there any way to get these folders to not be read only? Also, is this an issue, considering the text file is contained in the same directory as the pages from which the .txt file is being written?
hotblooded wrote:Notice: Undefined index: Semester in C:\wamp\www\newland\sem_select.php on line 37
Notice: Undefined index: Year in C:\wamp\www\newland\sem_select.php on line 38
file readfile written
Are you still generating those Notices? To me, that says that the Semester and Year values are NOT being passed in the $_POST array. Yet you say that you have printed out the variables and they are there? That's a disconnect for me. I don't know how both those things can be true at the same time.
Yes, I get these errors when I first open the page (i.e. before anything on the form is submitted). After I fill out the form and submit it, these errors go away because the variables then have a value. Hope this clears things up...
Now I uploaded it to a LAMP server (I'm using Vista) and it works just fine. This said, I believe it's not working on my machine because of the file permissions. The text file is not marked as read only; however, the directory it is in is read only. My issues are described better in one of my above posts. Let me know if these file permissions can be changed.
Oops! That could be the problem. Vista likes to take control and "hide" files ("to make for a better user experience", in Microsoft's terminology), which is why so many people, including me, have refused to install it. But that doesn't help you with your problem. Hopefully, someone here will have some experience with using Vista and be able to give you some advice.
Yeah it does get annoying sometimes...anyone else have any thoughts? Thanks for helping me figure out what the problem was...now I just have to get it to write properly...
I've also tried reading the file in another page and it isn't reading it right either...