Hi Everyone, I have a very strange issue with Posting a variable to a new page and reading the variable through GET -

I have used the same code many many times on different pages but for some reason, I am unable to GET the Post variable to use and display data from mysql database.

The code I am using to POST is

                                        <form method="post" action="checkout.php">
                                            <input type="text" name="producturl" id="producturl" value="<? echo $producturl; ?>">     
                                            <input type="submit" data-placement="bottom" rel="tooltip" class="btn btn-primary checkout" title="Add <? echo $producturl; ?> To Shopping Cart" value="Click To Continue Purchase">                                                
                                        </form>

The post variable is normally in a hidden type, I have placed it in a text to make sure I am seeing the correct variable, The variable is correct.

The checkoup page is where the problem is -
If I enter an incorrect DB name, I get an error as you would expect.

The strange problem is, If I change the include file from ../filename.php to ../../filename.php I get no error message - I would expect to see unable to load no such file name as location etc etc.

The code to GET the producturl is on checkout.php page is

if (isset($_POST['producturl'])) {
    $producturl = $_POST['producturl'];

But I am unable to read the variable, How can I test the variable is being posted correctly?

Just for clarification, if you send it with the POST method, you can only retrieve it with the POST method. If you send it with the GET method, you can only retrieve it with the GET method.

Since you're using a method="POST" form, it's good you're retrieving it with $_POST['producturl'] as opposed to $_GET['producturl'].

If you're using Google chrome, you can inspect the form submission. Here's how to do that.

  1. Press F12 to open Developer Tools
  2. Submit the form
  3. Click the Network tab
  4. Click the listing for checkout.php
  5. Click the Headers tab
  6. Scroll down to Request Headers
  7. Make sure producturl is being sent

Within your php code, you can do something like var_dump($_POST); to print out all the data the PHP code has retrieved from the form, and see if you can uncover what the problem might be.

Hay @Dani - Thanks very much, I will have a look through what you have suggested -
I have been looking at this for two days - I have the same process working on many different shopping carts and I just cant figure out what is issue is.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.