PHPBuilder - Beginner Debugging: For Your Eyes Only Page 4



RSS Twitter
Articles Tricks And Hacks

Beginner Debugging: For Your Eyes Only - Page 4

by: John Starkey
|
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.

<?php

/* 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:

<?php

$sql 
"INSERT INTO wherever (field1,field2) VALUES ('$field1','$field2')";
if ( 
$debug_ok == ) echo $sql;
else 
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.

« Previous Page
1
|
2
|
3
|
4
|
5
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
John Starkey

Comment:



Comment:

(Maximum characters: 1200). You have characters left.