0

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));
}
6
Contributors
21
Replies
84
Views
4 Years
Discussion Span
Last Post by chrisschristou
0

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);

Edited by broj1

0

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?

0

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();

0

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.

0

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;

0

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.

0

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.

0

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

0

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.

Edited by chrisschristou

0

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

0

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.

0

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

0

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

2

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.

Edited by João_5: added new code

0

// 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")

0

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??

0

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.

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.