Hi,
Please help me out.

1. Getting HYPERLINK value from page1 and saving in page2 using GET method.($re=$_GET[variable];)

2. Passing this value in -> select query

3. Displaying my output - correctly(in each and every value, there is an SUBMIT button.)

4. My Form Action is page2 itself.

5. Due to this, by submitting the form, my GET method value becomes NULL.

6.Displaying my output - incorrectly(selecting all NULL field values in WHERE CLAUSE)


Please help me out.Thanks in advance

Dani AI

Generated

A short, practical summary and checklist that fills the gap in the thread.

The reason the code value disappears is lifecycle: the first visit arrives with a query string (GET) and your page reads it fine. When the page is reloaded by submitting a form with method="post" the browser does not re-send the original query string unless you explicitly preserve it. As pointed out, propagating the value (for example with a hidden field) or reading both sources (GET then POST or REQUEST) fixes the submit case — that was the correct, minimal fix for the first problem.

For redirects and showing messages, use one of two reliable patterns depending on intent:

  • If you want to redirect and keep code, put the value on the redirect URL (as a query string) or store it in the session before redirecting so the target page can read it. Browsers will not magically keep your old GET parameters when you send a Location header without them.
  • If you want to stop and show an error immediately, don’t send a Location header: render the message and exit. Sending exit("text") after a redirect often won’t be seen because user agents follow the Location header; to reliably show a message after a redirect use a session “flash” or pass the message in the query string and display it on the landing page.

Quick troubleshooting and safety tips: confirm the form actually includes the hidden field (view source), check the form method and the submit-button name you test for (use request-method checks or test the button value correctly), always call header() before any output (or enable output buffering), and never place unsanitized request data directly into SQL — use prepared statements or cast IDs to integers to avoid injection. This approach keeps state clear, makes redirects predictable, and avoids the surprise of “missing” GET values.

Recommended Answers

All 15 Replies

Maybe you can specify your question with code samples. The first thing I think of is: does you form action contain Get-parameters? Or does it perform a Post? In that case use should question your form with $__POST[variable]. With $__REQUEST[variable] you can look for both Post an Get variables.

Hi,
In Page1

print "<a href=>click</a>";

In Page2

<?php
            ((isset(submit)) && (isset(submit)=="Upload file"))
            {
                 // code here 
            }
      $result=$_GET['code'];
      $qur="select name,lastname from table where id='$result'";
       ----code------
       html table tag opened
       while loop
       {
           displaying the output in browser -->first time correctly
           ------code goes here-------

            echo "<form action='page2.php' method='post' enctype='multipart/form-data'>";
  echo "<input type='hidden' name='id' value='$pid'>";
  echo "<input type='hidden' name='pe' value='$pp'>";
  echo "<input type='hidden' name='result' value='$result'>";
  echo "<td><input type='file' name='uploaded_file'></td>";
  echo "<td><input type='submit' name='Submit' value='Upload file'></td>";
  echo "</form>";
  echo "</tr>";
       }
       ---------------

     
      ?>

1.first time - displaying the output in the browser correctly from select query(getting the value from gets method -from select query WHERE $id='value').
2.Now - i am clicking submit button
3.displaying the output in the browser incorrectly from select query(NOW get method value become ZERO -displaying all values -from select query WHERE $id='').

Please help me out. Thanks in advance

Hi,

Inside SUBMIT button, am not facing any problem. Outside SELECT Query --its giving problem. How to sort out this.GET METHOD values -> why becoming empty string.

You are posting some variables with your second form but tries to read them with $_GET. You should use $_REQUEST[variable] to read both GET-params and POST-params.

facing problem in this

$result=$_GET['code'];

hi,

where i should use this $_REQUEST[variable] ? please point out in my above coding.

Use

$result=$_REQUEST['code'];

and add line

echo "<input type='hidden' name='code' value='pcode'>";

to your form

$result=$_REQUEST['code'];
echo "<input type='hidden' name='code' value='pcode'>";

You told to do as the above one,

$result=$_REQUEST['code'];
echo "<input type='hidden' name='code' value='$result'>";

value is $result
or
value is $pcode

Value can be of anything.

hi,
Really i thank of you.Its working.thanks a lot

OK, I didn't see that, I only saw 'pcode'. Is your problem solved? (sorry I was a little early)

yes, my problem is solved. Nearly, i spent half a day in this. From you, i learned about $_REQUEST method. thanks once again

Hi,

again i am facing the same problem, while redirecting the page

   if(condition)
   {
      header("Location:page2.php");
      exit("error");
   }

The $_REQUEST['variable'] -> getting null. How to fix this error.

:-)

if( condition )
{
    header("Location:page2.php?code=$pcode");
    exit("error");
}

i tries the same thing.its working.One more doubt, my exit() function showing error message in new browser window. So only, i am using header(), but this function redirect to PAGE2.PHP(home page) without showing any error message. If any error message means, i wants to stop execution of the script using exit("error message"). but "error message" should display in the same browser window

I don't understand you completely. Do you want the execution to stop if an error message contains any text? Or do you want sonething else? Your script is writing a header - that makes the browser to redirect in this case - and after that your PHP-script-executions is ordered to stop (by calling exit) while writing a message. Both the header and the messages are sent to the visiting client, that is first redirect and after is writing the message.
If you only wants to display the errormessage you should redirect. If you only wants to redirect don't write any message.

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.