Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Debugging PHP Code

Posted on 2011-02-18
7
Medium Priority
?
859 Views
Last Modified: 2012-08-13
Please provide some pointers on debugging PHP code. Having syntax errors in code, displays a completely blank screen and we have no idea where / what the problem is.

Examples:
1. Having <? php instead of <?php   at the top of the file

2. Having
    $categories[] = array('id' => $row['id'], 'name' => $row['name']); 'selected' => FALSE);
    instead of
    $categories[] = array('id' => $row['id'], 'name' => $row['name'], 'selected' => FALSE);

Thanks
0
Comment
Question by:caliea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 34928198
You can stick a die('made it to here');
In you code to check. Put it halfway, see if it makes it. Then keep splitting by Half till you find the problem.
0
 
LVL 8

Accepted Solution

by:
PranjalShah earned 1000 total points
ID: 34928309
You can add this two lines at top of your code..

ini_set('error_reporting',E_ALL);
ini_set('display_errors',1);
0
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 34928455
You can also use eclipse and have real debugging. But that's a whole other topic.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Assisted Solution

by:TimBare
TimBare earned 1000 total points
ID: 34928468
the error reporting is the easiest way to see what line it's dying on, but as far as pointers go, make sure you have the correct number of ()'s around lines, make sure you have your ; at the end of each line, stringing multiple variables together are separated w/ a .
ex:
$var1 = "abc";
$var2 = "def";
echo $var1.$var2;

Open in new window

would return "abcdef";

if you're using a for loop, make sure your counter is increasing ($i++;) otherwise it won't ever exit...

0
 
LVL 8

Expert Comment

by:ropenner
ID: 34928946
look in your web server's log file for the errors, once you've enabled error reporting.

eg. /var/log/apache2/error.log for Ubuntu Linux
      c:\wamp\logs\apache_error.log  windows WAMP install
0
 
LVL 5

Expert Comment

by:onemadeye
ID: 34929929
Placed this at the top of the PHP file to display errors
<?php
error_reporting(-1); // Put 0 to remove all errors

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34930278
Once you get the errors to show up, you will probably be able to find what is wrong rather quickly.  The comment at ID:34928309 is correct.

If you still have trouble debugging after that point, please post the code and the error message.

FWIW, parse errors only show up one-at-a-time.  The parser stops at the first error.  So if you have written a lot of code with a lot of parse errors in it, you may find that you need many iterations to get all the errors out!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question