2

I am wondering what is the best approach for debugging a $_POST PHP function, I seem to be losing data and the URL looks like a $_GET, I don't want to post the code as I want to learn how to properly debug PHP code if there is somewhat of a recipe on how to do this/some general guidelines I would appreciate them.

In short: After doing some reading for (oh about 8 hours trying to figure this out) I am really lost, what are the do's/don'ts?

2
  • use print_r($_POST); to print all post datas Commented Dec 6, 2012 at 12:06
  • $_POST is a variable not a function Commented Dec 6, 2012 at 12:08

4 Answers 4

3
var_dump($_POST);

will give you a list of all POST variables.

<?php
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>

will also work.

Sign up to request clarification or add additional context in comments.

9 Comments

It gave me a empty array with size 0. So I obviously did something wrong in my code hehe. Anyhow I will be sure to note that and use it aswell.
If it's an empty array, no POST variables exist. Make sure that your form is correct.
I just double checked, the method is POST, however what is interesting is that dumping _GET gives me all the values I wanted in _POST.
Are you sure that you've got method="post" and that the rest of your HTML is correct?
session doesnt keep _POST and _GET variables, it keeps only $_SESSION` variable with some session settings variables. I meant than when you submit form to another page with method="post", that page gets _POST data, but maybe in that page you again redirect somewhere?
|
1

Please try the following code.

print_r($_POST);

Comments

0

use print_r($_POST); to print all post datas

Comments

0

Check what's inside $_REQUEST:

var_dump($_REQUEST);

This will give you an array representation of you http request, and the method you are using [mostly GET/POST], in case you are using the wrong one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.