hello every body on daniweb
i have a problem who i had posted in past but it wasn't solve how can i redirect to another pages after insertind data into data base table, i did it but it work only on wanp in localhost but on web hosting (server) the data insert normal in table and the page just refresh here is the code

  $insertSQL = sprintf("INSERT INTO commande (sku, client, `date`, subtotal, total) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['sku'], "text"),
                       GetSQLValueString($_POST['client'], "text"),
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($_POST['subtotal2'], "double"),
                       GetSQLValueString($_POST['total'], "double"));

  mysql_select_db($database_marketbase, $marketbase);
  $Result1 = mysql_query($insertSQL, $marketbase) or die(mysql_error());

  $insertGoTo = 'order-line.php';
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: ".$insertGoTo));
}

Recommended Answers

All 21 Replies

Check out if the $insertGoTo variable has same value in both cases. Put this temporary line of code just before line 16:

die($insertGoTo);

Now see if the same value is displayed on the localhost and the web hosting server.

And also: you can simplify the header function like this:

header("Location: $insertGoTo);

i can't use the local host cause now i use diferent DB connection when i use the local i get only a big erroor code :D
i put the code before the line 16 and in the content is missing and i see onlony in side bar order-line.php?

This should redirect on any server.. If it should fail, I believe it will have to do with your redirect string.

header("Location: " . $insertGoTo); exit();

still same it don't redirect ... ;(

So what does the line die($insertGoTo); display?

I also noticed I had an error in my line of code (missing quote). The correct code is:

header("Location: $insertGoTo");

Please correct and also reply on my question above.

Try this to see if redirects are working:

header("Location: http://" . $_SERVER['HTTP_HOST']);

If you get redirected back to your root domain, you know redirects are working and the problem is with your redirect string;

thank you friends to reply me still same problem.
the die($insertGoTo); display the na of page who i want redirect order-line.php?
i try this header("Location: http://" . $_SERVER['HTTP_HOST']); like before the page just refresh.

Member Avatar for LastMitch

i have a problem who i had posted in past but it wasn't solve how can i redirect to another pages after insertind data into data base table, i did it but it work only on wanp in localhost but on web hosting (server) the data insert normal in table and the page just refresh here is the code

@chrisschristou

Your code is a bit confusing because of the the strings:

if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}

Maybe add this

if(!is_numeric($insertGoTo) && $insertGoTo != "") {
header("Location: $insertGoTo");
}

Not sure it would work either but would be more helpful if there is errors appearing.

thank you i'm at school when i go home i will try it and i will let you to know thank.

hello friends it don't work i have try to change the syntax where i have '' to "" nothing still same exist that other way ??
please help.

Can you post the whole script. Maybe there is a html output before header function, in which case the redirection won't work.

if output were the problem, he would be getting a suppression error.. Try: header("Location: http://google.com"); exit;

If you get redirected to google.com you know its your script. Then try var dump your query string and post so we know what is being passed to the header function.

i trie the code and i nothing i don't work the page refresh and no error just just the contnt of site is invisible

If you post the whole script we might get a bit closer to the resolution of your problem.

If order-online.php is in the same folder:
header("Location: order-line.php")
If order-online.php is in diferent folder:
header("Location: ../folder/order-line.php")
Or
header("Location: ../order-line.php")

Or you can use: echo "<script>history.go(-1);</script>"; Wich send you back to previews page.

Hope this helps, it works for me in local and in web.

// sends you back
echo "<script>history.go(-1);</script>";

// redirect to page on same folder
header("Location: order-line.php")

// Redirect to page on diferent folder
header("Location: ../folder/order-line.php")

// Redirect to page on diferent folder
header("Location: ../order-line.php")

sorry my friend to i wasn't online... for some reaseon i'm back i have try the last code you give me it don't work... i host my page on 1AND1 maybe is there the probleme??

Wich code did you use?
The 1st must be inside php code at the end of the page like:

<?php
echo "<script>history.go(-1);</script>";
?>

The other codes are simple html redirect codes, and them to must be inserted in the end of the page, just before </body>

You can try this too:

header('Location: ' . $_SERVER['HTTP_REFERER']);

They all work form me, specialy this one that i use in hta files.

Try this

echo "<script>location.replace('yourpage.php');</script>";

i used the first code header("Location: order-line.php") if i use the second it will bring 1 page back to historyc right??

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.