Friday, November 5, 2010

Debug PHP. Ask the Expert.

'Al-salam ala man tabea al-huda' (Salam upon those who follow 'the true guidance.')

Here I like to share the skills of debugging.

1.) print_r(); Use to display the value of an array or variable.

Example:

$arr1 = "This is a test";

echo "<pre>";
print_r($arr1);
echo "</pre>";
die();

2.) If u r expecting some result from your sql statement then you should print_r and die your sql statement. Then you have to copy paste the sql statement to your phpMyAdmin.

Example:
$mycity = Selangor;

$query = "SELECT * FROM Persons
WHERE City='.$mycity.' ";

print_r($query); die();

Then u will get:
SELECT * FROM Persons WHERE City= 'Selangor'.

Go to your phpMyAdmin, choose your database then click SQL.
Copy n paste the result to the SQL box then click Go.
Then find out the error. Use your brain. :)

That's All. All the Best. Any Questions you can ask here. InsyaAllah I will reply to you soon.