Hi everyone, I have a script running on my page that uploads a new image.
I am getting the information from the mysql ok, by using

if (isset($_POST['var'])) {

Once the vailidation is complete, at the moment I am using

header("Location: url.php");

to reload the page to display the new photo uploaded.
How do I include the above post var in the header Location url.php
Is it possible with open and close php tags

Dani AI

Generated

Brief, practical guidance and safer alternatives (adds to 's reply)

is correct that sending a redirect after the upload will refresh the view and can carry data to the next page via the URL. A few important caveats and better-practice options that address common problems seen with this pattern:

  • Redirects must be sent before any output is emitted; otherwise PHP will report "headers already sent." Use headers_sent() to detect this and avoid closing PHP/printing HTML before the redirect. (See PHP: headers_sent().)
  • Never expose sensitive data in the query string. For short, non-sensitive values an encoded query parameter works, but larger or private values should be passed as a database record id or via the session. filter_input() helps sanitize incoming values. (See PHP: filter_input().)
  • URL-encode any value placed into a query string to avoid broken URLs. Consider rawurlencode() when building the redirect target. (See PHP: rawurlencode().)
  • Use the Post/Redirect/Get pattern so form resubmission is avoided; issuing a 303 status after POST makes the browser fetch the next page with GET. (See HTTP 303 See Other.)
  • Always stop script execution after sending the Location header to prevent accidental output or logic running after the redirect.

Common troubleshooting: check for UTF-8 BOM or stray whitespace before the first <?php, inspect response headers in browser dev tools, and log headers_sent() output. For an image upload workflow, the most robust approach is: save the file and record, redirect with only the record id (or set a session flag), then let the display page look up and show the saved image. (See PHP: header() for details on redirects.)

Set your $_POST['var'] as a variable:

$var = $_POST['var'];

Then you can pass the variable through your url using:

header("Location: url.php?var=$var");

In url.php you can use the variable however you need by doing the following:

$passed_var = $_GET['var'];
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.