#native_company# #native_desc#

Beginner Debugging: For Your Eyes Only Page 4

By John Starkey
on October 30, 2002

Moving on, lets say we have a form that’s not working correctly. For some reason the data isn’t making it to
the database when the user hits submit. Once we’ve determined that the database is fine, we will need to
check our variables. In order to print these variables to the screen, we will test first that it’s ok, and
if so we’ll use a print_r on the form data.


/* test that debugging is ok and then print the variables */

if ( $debug_ok == print_r$_POST );


The above code should be placed within the target page, where you want the data to appear. This will
send all the values submitted via form, to the screen. Note: if you’re using the GET method in the form,
you’ll want to use $_GET in your print_r() function.
Another great way to use this is for echoing your SQL query, rather than sending it to the database:


$sql "INSERT INTO wherever (field1,field2) VALUES ('$field1','$field2')";

if ( 
$debug_ok == ) echo $sql;

mysql_query$sql );


This will help avoid a database cleanup once you’re finished debugging. Of course, you can use both
of the debug snippets simultaneously to get the maximum effect.