Where can I put var_dump in this code

I am trying to insert the below code snippet into the database but it is not entering and I don’t know what I did wrong.
Please, how can I output whatever I selected to the browser using <?PHP var_dump ?> or `

<?php if ($_POST) { print_r($_POST); } ?>

`
here is the code snippet:

<?php

                                    if(isset($_GET['add_cart'])){

                                       $ip_add = getRealUserIp();

                                                                      

                                       $p_id = $_GET['add_cart'];

                                       $product_qty = $_POST['product_qty'];

                              

                                       $size = $_POST['size'];

                                                                              

                                       $query = "insert into cart (p_id,ip_add,qty,size) values ('$p_id','$ip_add','$product_qty','$size ')";

                                      

                                       $run_query = mysqli_query($connection,$query);

                                                                              

                                       echo "<script>window.open('single-product.php?id=$p_id','_self')</script>";

                                                                                  

                                       }

                                                                      

                                   ?>

To correctly check for a post request use this test:-

if($_SERVER['REQUEST_METHOD'] == 'POST'){

}

To dump the content of the post array for debugging: var_dump($_POST);

You could put it after you build the query, so you can see if there’s a syntax error. You could copy the query as it’s built in $query into phpmyadmin and see what you get.

If you put exit() after the var_dump() or print_r() you can stop execution and prevent it from redirecting and wiping out your error message.

Did you intend to put a space after the size variable in your query? If it’s a numeric column, I’d expect that would get upset. But, you should use Prepared Statements instead of concatenating variables into your query like that, and then you wouldn’t need to worry about quotes at all.

Thanks.