nesiak Posted May 17, 2007 Share Posted May 17, 2007 this is the code i use to write to the beginning of a file! it reports an error at the line 6 what am i doing wrong ? error Parse error: parse error, unexpected T_VARIABLE in /home/www/nenadspp.freehostia.com/php/admin/writetofile.php on line 6 Code: <?php function writetofile() { $file=fopen("posts.php","r+"); $title = $_GET["title"] $text = $_GET["text"] $writte = "<h2>$title</h2> <br /> $text" fwrite (file$,$writte) } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/ Share on other sites More sharing options...
pocobueno1388 Posted May 17, 2007 Share Posted May 17, 2007 First off, you are missing your semi-colons ( after each line except one. I'm not all that familiar with file writing in PHP, so I can't help you with the rest. <?php function writetofile() { $file=fopen("posts.php","are+"); $title = $_GET["title"]; $text = $_GET["text"]; $writte = "<h2>$title</h2> <br /> $text"; fwrite ($file,$writte); //I think you were meaning to put the '$' at the beginning of the "file"... } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-255642 Share on other sites More sharing options...
nesiak Posted May 17, 2007 Author Share Posted May 17, 2007 Yup that solved the errors , how n00by of me But it still isn't writing to the file ? Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-255652 Share on other sites More sharing options...
nesiak Posted May 17, 2007 Author Share Posted May 17, 2007 Can anybody help me ? Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-255662 Share on other sites More sharing options...
pocobueno1388 Posted May 17, 2007 Share Posted May 17, 2007 Here is a nice tutorial for you =D http://www.tizag.com/phpT/filewrite.php Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-255678 Share on other sites More sharing options...
nesiak Posted May 17, 2007 Author Share Posted May 17, 2007 The problem was that i never called the function (i had this error twice in one day!) Now another error came to notice Warning: fopen(posts.php): failed to open stream: HTTP wrapper does not support writeable connections. in /home/www/nenadspp.freehostia.com/php/admin/writetofile.php on line 4 Warning: fwrite(): supplied argument is not a valid stream resource in /home/www/nenadspp.freehostia.com/php/admin/writetofile.php on line 8 I'm stumped Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-255708 Share on other sites More sharing options...
nesiak Posted May 17, 2007 Author Share Posted May 17, 2007 Can anybody help me ? Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-255737 Share on other sites More sharing options...
hitman6003 Posted May 17, 2007 Share Posted May 17, 2007 [code]$file=fopen("posts.php","are+"); WFT is "are+"? change it to: [cdoe]$file=fopen("posts.php","a+");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-255745 Share on other sites More sharing options...
nesiak Posted May 17, 2007 Author Share Posted May 17, 2007 that is a typo , i opened the file for read/write (r+) Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-255762 Share on other sites More sharing options...
pocobueno1388 Posted May 17, 2007 Share Posted May 17, 2007 Did changing that fix the problem? Make sure the files permission that you are trying to write to is set to "777". Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-255771 Share on other sites More sharing options...
nesiak Posted May 17, 2007 Author Share Posted May 17, 2007 no.... that doesn't work neither Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-255780 Share on other sites More sharing options...
dmikester1 Posted May 17, 2007 Share Posted May 17, 2007 If you want to write to the beginning, shouldn't you be using 'w+' or 'x+'? 'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 'x+' Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files. Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-255900 Share on other sites More sharing options...
nesiak Posted May 18, 2007 Author Share Posted May 18, 2007 No R+ is read/write, w+ would delete the contents of the file before writing to it , i need to preserve the file contents that's why i'm using r+ Fixed the problem, i was trying to write to a url and that is not possible ! Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-256151 Share on other sites More sharing options...
jitesh Posted May 18, 2007 Share Posted May 18, 2007 <?php function writetofile() { chmod("posts.php",766); $file=fopen("posts.php","w+"); $title = $_GET["title"]; $text = $_GET["text"]; $writte = "<h2>$title</h2> <br /> $text"; fwrite ($file,$writte); //I think you were meaning to put the '$' at the beginning of the "file"... } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51867-solved-writing-to-file/#findComment-256155 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.