When getting the basic logic working I recommend you do a couple of things.
1 display all errors
2 var_dump any variables you are passing round
3 if you are building sql statements, then build them into a string, and echo it onto your screen as you work
PHP Code:
<?php
// first lines
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
// after you are expecting a form to be handled
var_dump( $POST ); // or GET, COOKIE or whatever
// building a query, which could go horribly wrong anywhere
$guy = "guy";
$sql = "select stuff from marriage where husband = '$guy' and wife = 'madonna'";
// take a look at it, paste it into phpmyadmin or whatever
echo $sql ;
?>
comment out each line when it gets on your **ts.
and REMOVE the top lines when you publish it, or change it to log errors instead.
Some ppl have a Debug flag which you can link to a local file too, and it can be used to echo this kind of info onto the screen.
PHP Code:
$DBG =0;
if( file_exists( "/local.flag") ) $DBG = 1;
// Then do error reporting etc
// or things like this
if( $DBG ) echo $sql ;
Something similar to that anyway, so yes, var_dump() is your friend, and if you use arrays its your best friend.
Some of the reasons why can be found in this chart. What is true in PHP? Before you do any conditional forks, make sure you know what you are checking against.
This fact, using arrays to their full potential and properly addressing security are probably the 3 most important lessons to learn.
Bookmarks