Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kilpajr

macrumors regular
Original poster
Aug 24, 2004
122
0
Auburn, AL
I am taking a class where we are designing an e-commerce website using html and php. This is my first experience using php (although I have experience with c and java) so I tend to make a lot of syntax errors as well as other errors. When there is a problem, the page simply fails to load. Is there a way to find where a problem is in php code?
 

haiggy

macrumors 65816
Aug 20, 2003
1,328
76
Ontario, Canada
I'm not sure if this finds errors, but
if you don't use it already (or if you have to use a specific app) you should try SubEthaEdit. You can find it at versiontracker.com

I find it a good program for programming.
 

kilpajr

macrumors regular
Original poster
Aug 24, 2004
122
0
Auburn, AL
Thanks for the recommendation. I just tried it but I think I like HyperEdit better. It is actually showing a parse error, whatever that is. What's wrong with this?
Code:
GLOBAL $birth_month_text;
$birth_month_text = "January";
 

Thom_Edwards

macrumors regular
Apr 11, 2003
240
0
kilpajr said:
I am taking a class where we are designing an e-commerce website using html and php. This is my first experience using php (although I have experience with c and java) so I tend to make a lot of syntax errors as well as other errors. When there is a problem, the page simply fails to load. Is there a way to find where a problem is in php code?

check your php.ini file and you will find an error-reporting section. it's pretty well documented, so i'm sure you'll be able to see exactly what kind of errors you want to see. i can't remember for certain, but i think you will have to restart apache or restart your computer after you change the file for the changes to take affect.
 

Knox

Administrator
Staff member
Jul 1, 2002
1,267
1
UK
kilpajr said:
Thanks for the recommendation. I just tried it but I think I like HyperEdit better. It is actually showing a parse error, whatever that is. What's wrong with this?
Code:
GLOBAL $birth_month_text;
$birth_month_text = "January";

Nothing wrong with that (assuming that code is in a function and that is the first thing in the function), however, PHP doesn't necessarily report the correct line number with error messages. Or rather, it doesn't report the line number that the mistake is on - for example, if you did

Code:
function my_function ()
    GLOBAL $birth_month_text;
    $birth_month_text = "January";
}

It would report line 2 as the error, when in fact the error is on line 1 (I missed out the { ). Parse error just means you did something wrong that stops the script from running - it should give you a bit more detail, for example :

Parse error: parse error, unexpected T_GLOBAL, expecting '{' in /home/knox/public_html/current/v5.nightb4.com/dev/test2.php on line 2

Which is the error generated for the code above. The second part gives more indication of what you did wrong.

Can't really help with debugging tools other than the built in errors - I don't tend to use any - I've just learnt the likely place for errors from experience.
 

kilpajr

macrumors regular
Original poster
Aug 24, 2004
122
0
Auburn, AL
I finally found my problem. Since I was just trying to do it quickly, I didn't indent and left out a bracket. I was confused about the error because it was reported near the beginning of the code and the missing bracket was at almost the very end.

One thing that was odd was that I was getting a parse error on a line of code in a switch statement that I knew was correct. I lined up the case statement and the code underneath it and the parse error moved to the next case statement. Once I had all of the case statements and the corresponding code lined up, I didn't have a parse error anymore. Is there a reason for this?
 

jeremy.king

macrumors 603
Jul 23, 2002
5,479
1
Holly Springs, NC
kilpajr said:
I finally found my problem. Since I was just trying to do it quickly, I didn't indent and left out a bracket. I was confused about the error because it was reported near the beginning of the code and the missing bracket was at almost the very end.

One thing that was odd was that I was getting a parse error on a line of code in a switch statement that I knew was correct. I lined up the case statement and the code underneath it and the parse error moved to the next case statement. Once I had all of the case statements and the corresponding code lined up, I didn't have a parse error anymore. Is there a reason for this?

indentation had nothing to do with it. The left out brace was your problem child.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.