PHP/MySQL FAQ and Tips

This page provides tips and answers to frequently asked questions on PHP and MySQL.

Why won’t my PHP page load in my browser?

  • Make sure that you have your PHP development environment (such as XAMPP) installed and running.
  • Make sure that your Apache Web Server is also running (In XAMPP, open the XAMPP Manager, click on the Manage Servers tab, select Apache Web Server, and click on Start (and also turn on MySQL Database if you intend to use that).
  • Make sure that the webpage ends with the correct extension (eg. myfile.php) and that it is in the correct directory eg. XAMPP/htdocs/myfile.php.
  • Make sure your htdocs folder is intact. If using XAMPP, you will have a htdocs folder inside the XAMPP installation folder. It will contain all of your PHP files that you write, but it will also contain a lot of other important file such as the configuration file. Do not alter the structure of your htdocs folder or delete/move any other files!

My Apache web server won’t start. Why?

  • Make sure there are no other programs running that may clash with your PHP environment (eg. XAMPP). It may be using the same ports that are require by XAMPP. Skype is known to use the same ports and can cause issue if running. Make sure it is completely closed (go to Task Manager in Windows, select the conflicting program and click End Task; or Force Quit the program on Mac OS).
  • Make sure your htdocs folder is in the correct location and has not been moved or deleted. Make sure the files inside your PHP environment installation’s (eg. XAMPP) folder have not been moved or deleted, including the htdocs folder.
  • Make sure your httpd.conf configuration file points to the correct directory if you have moved your htdocs folder. Make sure you also have privileges to access this folder if you are not an administrator.

I’m getting syntax errors.

  • Check the spelling of your statements or keywords.
  • Make sure your statements all end with a semicolon (;) and that you close brackets and quotation marks where necessary.
  • Make sure you have escaped quotation marks inside strings.
  • Make sure you use commas or periods where need to separate items (eg. in string concatenation).
  • Also make sure that you variable names follow the rules of variable naming.

I get errors when I declare a new variable.

Check the following:

  • Names of variables must begin with a $ dollar sign
  • Letters, numbers and underscores can be used in variable names but no spaces
  • The first chracter of a variable name cannot be a number
  • Variable names are case-sensitive (that means, $myvariable, $myVariable, and $MYVARIABLE are three different variables).