Database design: keys, relationships and normalization
Design tables that avoid duplicated data: primary keys, foreign keys, one-to-many and many-to-many relationships.
See every problem on your computer, and hide them from visitors on the live site.
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');Never show errors to visitors. They reveal file paths and sometimes passwords. Log them instead:
ini_set('display_errors', '0');
ini_set('log_errors', '1');
ini_set('error_log', __DIR__ . '/logs/php-error.log');Keep the logs folder out of public access.
var_dump($value); // type and value
echo '<pre>', print_r($arr, true), '</pre>';
error_log('Reached step 3: ' . json_encode($data));A message has three useful parts: what went wrong, the file, and the line number. Start at that line, and also look at the line above it (a missing ; is reported on the next line).
Undefined variable or Undefined index: you used something before setting it. Use ?? for a default: $_GET['id'] ?? 0.headers already sent: something was printed before header() or session_start(). Look for spaces before <?php.Call to undefined function: a typo, or a missing extension.Design tables that avoid duplicated data: primary keys, foreign keys, one-to-many and many-to-many relationships.
A folder layout and a few habits that keep a growing PHP site tidy, secure and easy to maintain.