| View previous topic :: View next topic |
| Author |
Message |
Trikster
Joined: 15 Jul 2007 Posts: 1224 Location: Enterprise, Alabama
|
Posted: Sat Jan 05, 2008 11:59 pm Post subject: PHP Errors - Just Started Learning It |
|
|
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 |
|
 |
Elevator_Hazard
Joined: 28 Oct 2006 Posts: 302 Location: US
|
Posted: Sun Jan 06, 2008 12:39 am Post subject: |
|
|
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  |
|
| Back to top |
|
 |
Trikster
Joined: 15 Jul 2007 Posts: 1224 Location: Enterprise, Alabama
|
Posted: Sun Jan 06, 2008 1:02 am Post subject: |
|
|
Success! Now I have to get it to append the data to the new file. _________________ ScriptPad | ~dieom | dieom | izwian2k7 | Ian | God |
|
| Back to top |
|
 |
Elevator_Hazard
Joined: 28 Oct 2006 Posts: 302 Location: US
|
Posted: Sun Jan 06, 2008 1:31 am Post subject: |
|
|
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 I guessed the file_put_contents url)
Happy coding  _________________ Changed siggy at request of ahklerner  |
|
| Back to top |
|
 |
Trikster
Joined: 15 Jul 2007 Posts: 1224 Location: Enterprise, Alabama
|
Posted: Sun Jan 06, 2008 3:08 am Post subject: |
|
|
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 |
|
 |
Elevator_Hazard
Joined: 28 Oct 2006 Posts: 302 Location: US
|
Posted: Sun Jan 06, 2008 3:17 am Post subject: |
|
|
Just remember those semi-colons
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  |
|
| Back to top |
|
 |
Trikster
Joined: 15 Jul 2007 Posts: 1224 Location: Enterprise, Alabama
|
Posted: Sun Jan 06, 2008 3:19 am Post subject: |
|
|
Error landers usually omit blank lines. _________________ ScriptPad | ~dieom | dieom | izwian2k7 | Ian | God |
|
| Back to top |
|
 |
Elevator_Hazard
Joined: 28 Oct 2006 Posts: 302 Location: US
|
Posted: Sun Jan 06, 2008 3:22 am Post subject: |
|
|
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  |
|
| Back to top |
|
 |
Trikster
Joined: 15 Jul 2007 Posts: 1224 Location: Enterprise, Alabama
|
Posted: Sun Jan 06, 2008 3:43 am Post subject: |
|
|
Give me a sec. _________________ ScriptPad | ~dieom | dieom | izwian2k7 | Ian | God |
|
| Back to top |
|
 |
|