User not logged in - login - register
Home Calendar Books School Tool Photo Gallery Message Boards Users Statistics Advertise Site Info
go to bottom | |
 Message Boards » » Debug this short php script Page [1]  
Redtaco4x4
All American
1410 Posts
user info
edit post

<?php

$emailAddress = $_POST["emailadd"];

if(!$emailAddress) // If email address is not entered show error message
{
echo "Please enter your email address.";
exit;
}
else
{
$filename = "guestlist.txt"; // File which holds all data
$content = "$emailAddress\n"; // Content to write in the data file
$fp = fopen($filename, "a"); // Open the data file, file points at the end of file
$fw = fwrite( $fp, $content ); // Write the content on the file
fclose( $fp ); // Close the file after writing

if(!$fw) echo "Couldn't write the entry.";
else echo "Successfully wrote to the file.";
}
?>

Here is the error that I get:
Parse error: parse error, unexpected T_VARIABLE in /Library/Apache2/htdocs/submit.php on line 3

I can't figure out why it is giving this error. From searching online, most get this error when a space or a semicolon is messed up. What's going on here?

1/28/2006 4:21:40 PM

joe17669
All American
22728 Posts
user info
edit post

I just ran your code and it worked fine on my end...

Output: Successfully wrote to the file.

1/28/2006 4:36:48 PM

jackleg
All American
170957 Posts
user info
edit post

use periods

1/28/2006 4:58:50 PM

Redtaco4x4
All American
1410 Posts
user info
edit post

Should this kind of stuff be platform dependent? I'm sure I'll get quoted as this being the problem because you people are just you people, but I'm using Safari and Firefox on my Mac and I get this error.

1/28/2006 5:41:34 PM

Noen
All American
31346 Posts
user info
edit post

what version of php? Looks fine to me too, works on my windows pc and on my linux webserver.

1/28/2006 5:49:23 PM

joe17669
All American
22728 Posts
user info
edit post

solution: don't use a Mac jk i used mine to test it (safari only, no apache on it)

nah, do like ^ said and check your PHP version. Noen tried it on his linux server, I did it on my Windows server (apache), and it worked on both. Is your webserver running on the Apple or somewhere else?

1/28/2006 8:48:04 PM

jackleg
All American
170957 Posts
user info
edit post

have you tried adding a period

or doing this

$emailAddress = ($_POST['emailadd']);


it should work like you have it, but if its getting picky, i think you have to separate it so that it knows its about to read from the array.

1/28/2006 11:48:26 PM

Redtaco4x4
All American
1410 Posts
user info
edit post

php 4.3.9 and Apache 2.0.52. I probably need to update. Putting the () around it worked, but now:

Parse error: parse error, unexpected '{' in /Library/Apache2/htdocs/submit.php on line 6

It's amazing how I try to do something simple and it turns way to complicated.

1/29/2006 7:32:59 AM

Redtaco4x4
All American
1410 Posts
user info
edit post

going back and using Apache 1.3.33 (default personal websharing version), I just get a:

Error 405: The requested method POST is not allowed for the URL /submit.php.

[Edited on January 29, 2006 at 7:51 AM. Reason : ]

1/29/2006 7:47:22 AM

State409b
Suspended
490 Posts
user info
edit post

then you need to enable the apache option execssi or maybe execcgi for submit.php

[Edited on January 29, 2006 at 10:11 AM. Reason : *]

1/29/2006 10:09:18 AM

Shaggy
All American
17820 Posts
user info
edit post

all it needs to work in is IE.

dont worry about the rest

1/29/2006 12:15:02 PM

jackleg
All American
170957 Posts
user info
edit post

im writing a web browser in BASIC

1/29/2006 12:18:30 PM

Noen
All American
31346 Posts
user info
edit post

What program are you using to edit/create this file?

I had a HELL of a time doing php dev on my work Mac a year or two ago using BBEdit. Turns out it was using some weird fucking text encoding and php/apache did not like it one bit.

Try rewriting the file by hand (it's short, so shouldnt take but a minute) in Dreamweaver or some other text editor.

Also grab a hex editor and check the file, ill see if I can remember the one I was using.

1/29/2006 7:51:43 PM

Redtaco4x4
All American
1410 Posts
user info
edit post

this was written using Text Wrangler. A coworker uses it and has no problems with it at all.

1/30/2006 6:40:35 AM

OldManRamble
New Recruit
48 Posts
user info
edit post

TextWranger, BBedit, et al. should be fine - just make sure you are using Unix Line Breaks (File->Preferences...,Text Files:Saving, set Default Line Breaks: to Unix).

PHP seems to hate non-Unix line feeds, at least on the Macintosh. I avoid anything having to do with "server" on Windows, so I can't help you there, but I'd make sure on Windows -- if you absolutely have to use Windows -- that the Line Breaks are either DOS/Windows - or hopefully Unix.

Ob-opinion: Every text editor you use on the Macintosh should be set to save text files with Unix line breaks. If the editor doesn't let you do that, find a new one.

p.s. My default encoding has always been Western (Mac OS Roman).

[Edited on January 30, 2006 at 11:32 AM. Reason : p.s.]

[Edited on January 30, 2006 at 11:33 AM. Reason : speeling]

1/30/2006 11:31:33 AM

Noen
All American
31346 Posts
user info
edit post

^Good catch, I never could get the line breaks to work in BBEdit. If I ever find myself developing on a Mac again, I'll have to give that a shot.

1/30/2006 3:38:01 PM

Redtaco4x4
All American
1410 Posts
user info
edit post

I found a fix for this problem. TextWrangler has the "zap gremlins" option and that removed all of the hidden characters. I also wasn't saving it in the correct format. I ran zap gremlins, saved it with unix line breaks in Western (Mac OS Roman) and now it works perfectly. Word um up TWW!

1/31/2006 5:24:42 PM

 Message Boards » Tech Talk » Debug this short php script Page [1]  
go to top | |
Admin Options : move topic | lock topic

© 2024 by The Wolf Web - All Rights Reserved.
The material located at this site is not endorsed, sponsored or provided by or on behalf of North Carolina State University.
Powered by CrazyWeb v2.38 - our disclaimer.