AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

PHP Errors - Just Started Learning It

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> General Chat
View previous topic :: View next topic  
Author Message
Trikster



Joined: 15 Jul 2007
Posts: 1224
Location: Enterprise, Alabama

PostPosted: Sat Jan 05, 2008 11:59 pm    Post subject: PHP Errors - Just Started Learning It Reply with quote

Ok, I know of no PHP help websites with forums, and Titan is online..So, my current host does not offer quick file editing, so I am trying to make some stuff to do so. I currently have the following script in the page with errors:

Code:
<?php

   $file = $_POST["file"]
   $fh = fopen ($file, r+)
   $contents = fread ($fh, filesize ($file));
?>

<link rel="stylesheet" href="css/style.css" type="text/css">

<div id=text>
<textarea cols="43" rows="10"><?php echo "$contents"; ?></textarea>


It says the error is:

Quote:
Parse error: parse error, unexpected T_VARIABLE in /homepages/41/d230292756/htdocs/edit.php on line 4


Which is $contents = fread ($fh, filesize ($file));. To what I know, this is correct. Am I wrong?
_________________
ScriptPad | ~dieom | dieom | izwian2k7 | Ian | God
Back to top
View user's profile Send private message
Elevator_Hazard



Joined: 28 Oct 2006
Posts: 302
Location: US

PostPosted: Sun Jan 06, 2008 12:39 am    Post subject: Reply with quote

Heh I love php...

You are missing your semi-colons, its expecting a semicolon not a variable reference so that's why you are getting that error. You got it right though at the $contents = fread ($fh,filesize($file));

Also you don't really have to do all that to read a file, you can use file_get_contents() which does all that for you.
_________________
Changed siggy at request of ahklerner Very Happy
Back to top
View user's profile Send private message
Trikster



Joined: 15 Jul 2007
Posts: 1224
Location: Enterprise, Alabama

PostPosted: Sun Jan 06, 2008 1:02 am    Post subject: Reply with quote

Success! Now I have to get it to append the data to the new file.
_________________
ScriptPad | ~dieom | dieom | izwian2k7 | Ian | God
Back to top
View user's profile Send private message
Elevator_Hazard



Joined: 28 Oct 2006
Posts: 302
Location: US

PostPosted: Sun Jan 06, 2008 1:31 am    Post subject: Reply with quote

file_put_contents() should do the trick.

And when you say append if you want it to write the data to the end of the file you can have the 3rd parameter (that's the one where you put your flags) you do FILE_APPEND so like... file_put_contents(textorfilename,textorfilename,FILE_APPEND); I think (I said textorfilename because I don't know which parameter is which and I'm too lazy to look it up Razz I guessed the file_put_contents url)

Happy coding Very Happy
_________________
Changed siggy at request of ahklerner Very Happy
Back to top
View user's profile Send private message
Trikster



Joined: 15 Jul 2007
Posts: 1224
Location: Enterprise, Alabama

PostPosted: Sun Jan 06, 2008 3:08 am    Post subject: Reply with quote

Just got another one.

Script:

Code:
<?php

   If ($_POST["nfName"] = "") {
      $nFile = $_POST["fName"];
      $fh = fopen($nFile, 'w')
      fclose($fh);
   } else {
      $nFile = $_POST["nfName"]
      $fh = fopen($nFile, 'w')
      fclose($fh);
   }
?>


Error:

Quote:

Parse error: parse error, unexpected T_STRING in /homepages/41/d230292756/htdocs/save.php on line 6


Line 6: } else {
_________________
ScriptPad | ~dieom | dieom | izwian2k7 | Ian | God
Back to top
View user's profile Send private message
Elevator_Hazard



Joined: 28 Oct 2006
Posts: 302
Location: US

PostPosted: Sun Jan 06, 2008 3:17 am    Post subject: Reply with quote

Just remember those semi-colons Very Happy

Its hard to remember them if you are used to a language that doesn't use them at the end of most lines (ex: ahk). I still forget them a lot...

Also line 6 is fclose($fh); it looks like.
_________________
Changed siggy at request of ahklerner Very Happy
Back to top
View user's profile Send private message
Trikster



Joined: 15 Jul 2007
Posts: 1224
Location: Enterprise, Alabama

PostPosted: Sun Jan 06, 2008 3:19 am    Post subject: Reply with quote

Error landers usually omit blank lines.
_________________
ScriptPad | ~dieom | dieom | izwian2k7 | Ian | God
Back to top
View user's profile Send private message
Elevator_Hazard



Joined: 28 Oct 2006
Posts: 302
Location: US

PostPosted: Sun Jan 06, 2008 3:22 am    Post subject: Reply with quote

I can get on the ahk irc (freenode.net... #autohotkey) if you want to talk to me in chat room.
_________________
Changed siggy at request of ahklerner Very Happy
Back to top
View user's profile Send private message
Trikster



Joined: 15 Jul 2007
Posts: 1224
Location: Enterprise, Alabama

PostPosted: Sun Jan 06, 2008 3:43 am    Post subject: Reply with quote

Give me a sec.
_________________
ScriptPad | ~dieom | dieom | izwian2k7 | Ian | God
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> General Chat All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group