Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 27-02-2009
Member
 
Join Date: May 2008
Posts: 2,293
PHP Frequent errors

Frequent PHP errors

Suppose there is an error in your script and your script is only half or even not at all. Say that your PC does not make a mistake in the script because a computer is never wrong. What should you look at a mistake and how you get the problem? In any event, not a topic on the forum where you display the error and your whole code with the question like "Dissolve this out for me please." so Go look for yourself what the problem might be and if you want you can obviously go to the forum.

What errors are there?

1.Fatal error
Error while running the script. The execution of the script should be stopped.
Quote:
Fatal error: Call to undefined function mysql_connect () in / path / vb.php on line 3


2.Warning

An error during the execution of the script. The fault is not so bad that the script must be stopped.
Quote:
Warning: session_start (): Can not send session cookie - headers already sent by (output started at / path / vb.php: 2) in / path / vb.php on line 3


3.Parse error
A compilation error. This occurs when you use a wrong syntax. The script can not be started.
Quote:
Parse error: parse error, unexpected T_STRING, expecting ',' or ',' in / path / vb.php on line 2

4.Notice

Whether this error is shown is the configuration of your server (details on next page). these are just observations, which could indicate an error, but it does not.
Quote:
Parse error: parse error, unexpected T_STRING, expecting ',' or ',' in / path / vb.php on line 2
As you can see PHP always says what kind of error it is, what is the error, in which file the error occurred and the line where the error occurred.
Note: PHP is not always the correct line number where the error occurred. It is in these cases helpful to the previous and next line of error checking.

Say you get an error


This means that you have a full white screen.
You can then top of your script put the following:
php:
Quote:
<?PHP
error_reporting ( E_ALL );
ini_set ( "display_errors" , "1" );
?>
This ensures that ALL errors and messages on the screen will be printed, so even there are error messages appear that you do not normally see. On a test server can be very useful if you want to clean scripting. It is not recommended it to a production server.

More information about the error_reporting function and how to configure php.ini can be found in the php manual
Reply With Quote
  #2  
Old 27-02-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: PHP Frequent errors

What to do if you have errors? => Debugging
Test your page in pieces by regularly printing some information so you can easily see where the script is the true wrong. For example, if nothing happens to your variables, you print variable than once to see whether that is the right value.

Often makes mistakes in subarrays, eg requesting something with $ array [subarray] or $ array [ '$ i'].
Remember also that programming languages start counting at 0 and not 1!

Debugging arrays:


php:
Quote:
<?PHP
echo "<pre><code>" ;
echo print_r ( $array , true );
echo "</code></pre>" ;
?>

The <pre> and <code> ensure that your array legible and easy to navigate. The print_r () to print the entire array. It is especially useful for the arrays $ _POST, $ _GET $ _SESSION, $ _COOKIE, and $ _FILES in this way to print.

Debugging SQL Queries:
Also working with SQL queries is sometimes useful to echo in your document to see what query your SQL server now receives. A solution could include:

php:
Quote:
<?PHP
$query =
mysql_query ( $query ) or die( 'Query: ' . $query . '<br><br>' . mysql_error ())
?>
Reply With Quote
  #3  
Old 27-02-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: PHP Frequent errors

Frequent PHP errors

Here we give an overview of the errors that are very often, and however easily remedied.

A) forget:
This is a common mistake. If you control structures like while, for, foreach, if / else are working and a final accolade forget you get an error in the last brace of the script, or after no more braces are, on the last line of the script.

This is a difficult mistake because sometimes your whole script should look for the fault to be found. Some tips to avoid this error: make your code indentation with each level you make it so you can quickly see which brace belongs to which structure and where there is a missing brace.
Another important tip is that if you work with a control structure, you immediately after you put the opening brace is the final accolade places. This ensures that they subsequently can not forget.

; Or forgotten: typed:

In this case you get an error message on the next line.

'And' swap:

You often against people who have a string with double quotation stabbing begin with a single quotation stabbing end. This does not! You must finish with the same string citation stabbing started as you are.
Remember this definitely:
Within double quotes are parsed variables. You should always beware of double quotes: you must often dangerous characters ( "$ ...) escaping through a \ continue)
Within single quotes, the string literal as text appearance, there are no variables parsed. It is therefore no need for dangerous characters ( "$ ...) to escape.

Headers already sent by:

This error is common when your cookies, sessions or header refers ring. These functions must be called before any HTML is executed. It should therefore not sent information to the client when you use these functions.
protecol works with the http headers with information about the object to questions
once you start sending the contents of a document, the html so (one is enough space or enter). header can not be changed and you get a php error.
that is to solve the brackish method ob_start () and ob_flush and (), that hold the page at all on the server until you do flusht at the bottom of the script. Not recommended for slow connections or a large website so.
A better solution is just to important php calculations and adjustments to the header to obtain data that is sent to the client.

also set cookie in the header
header example of wikipedia
Code:
Quote:
HTTP/1.1 200 OK
Date: Mon, 23 May 2005 22:38:34 GMT
Server: Apache/1.3.27 (Unix) (Red-Hat/Linux)
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
ETag: "3f80f-1b6-3e1cb03b"
Accept-Ranges: bytes
Content-Length: 438
Connection: close
Content-Type: text / html; charset = UTF-8
Reply With Quote
  #4  
Old 27-02-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: PHP Frequent errors

Variables echoing

The echoing of variables and html tags (double quotes) is often found difficult by beginners and advanced. there are a few handy ways to remedy.

For easy html tags to display is the easiest to strings between sinlequotes ( ') to double quotes ( ") m which saves a lot of problems with scripts
What often happened to be echoing variables is that people simply use the tags:
php:
Quote:
<?PHP
$string = "text: $var, Nog meer text" ;
?>
as you see is the variable hard to tell the other red text and also not very smart. a better way to variables and functions outside the quotes' to continue, which may in this way:
php:
Quote:
<?PHP
echo $var ;
$string = 'text' ;
$string = $var . $var ;
$string = $var . ' text ' . $var ;
$string = 'text' . 'text' ; //erg onnodig
//bijv.
echo '<span style="color: #FF0000">' . $var . '</span>' ;
?>

The disadvantage of using single quotes is that there are no escaped charactars "are parsed, a solution may, for example, are using a constant, which can not single and double quotes need to be used together.

php:
Quote:
<?php
define ( "NL" , "\n" );
$string = '<td>' . $var . '</td>' . NL ;
?>
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "PHP Frequent errors"
Thread Thread Starter Forum Replies Last Post
Google Chrome 13 on Linux showing frequent Aww Snap errors LavinaD Technology & Internet 4 14-09-2011 10:28 PM
MTS Mblaze frequent disconnection S-Waugh India BroadBand 4 21-11-2010 05:21 AM
Frequent Restarts (Bugcheck) Please Help!! vinay016 Operating Systems 1 04-08-2009 10:29 PM
Most frequent use of your Computer? Ekavir Polls & Voting 8 06-10-2008 07:39 PM
Frequent Screen Freeze EvChrysler300 Vista Help 18 22-09-2008 12:13 PM


All times are GMT +5.5. The time now is 12:11 AM.