Hi All, I'm quiet new to php. We are trying to submit a form for edit operation. When the form is posted, i'm trying to concatenate the existing query string. But the redirection is not working. Here is the below code. Pls help if ($_POST['doSubmit'] == 'Submit') { // confirm that the 'id' value is a valid integer before getting the form data if (is_numeric($_POST['id'])) { // get form data, making sure it is valid $id = $_POST['id']; $user_email = mysql_real_escape_string(htmlspecialchars($_POST['user_email'])); $user_name = mysql_real_escape_string(htmlspecialchars($_POST['user_name'])); $user_ban = mysql_real_escape_string(htmlspecialchars($_POST['user_ban'])); /* Now update user data*/ mysql_query("update email_users set email='$user_email', name='$user_name', banned = '$user_ban' where id='$id'"); $delqry = "delete from list_emailuser where emailid = '$id'"; mysql_query($delqry); if(!empty($_POST['list'])) { foreach ($_POST['list'] as $lsid) { $lsid = filter($lsid); mysql_query("insert into list_emailuser(emailid,listid) values('$id','$lsid')"); } } $ret = $_SERVER['PHP_SELF'] .'?' . $_POST['query_str']; header("Location: $ret"); exit; } else { $err[]= "Unable to Update."; } }
Can't tell if serious. The line you have in that snippet is: [COLOR=#111111]("Location: $ret");[/COLOR] Code (markup): Not: header[/COLOR] [COLOR=#111111]("Location: $ret");[/COLOR] Code (markup): Also, in the future please format your code with the [ code ] tags. edit: forgive me. DP/vBulletin seems to behave weird when you insert header in to the page/code snippet. How odd. Anywho, make sure that block of code is being executed. Like TeemuGr stated, before using the header function, try something like: echo 'about to redirect'; exit; Code (markup): And see if it gets executed. If it doesn't, there's your problem. If it does, we can discuss where to proceed from there.
I checked with echo statement before header. It works fine. Unable to catch the bug but the syntax looks fine.
Output the value of $ret and let me know what it is. Can you also send me the URL so I can take a look at the HTTP headers being sent/received?
this is a common header() problem. Try deleting all the line spaces between codes. Hope it will work. Thankyou
you don't have the function name header("location: $ret"); PHP: and then I would put a exit; PHP: straight after it
UTF-8 BOM also causes header function not to work. If you open PHP file in a Notepad and save it, it will almost certainly have a UTF-8 BOM. Use some other editor, which does not leave UTF-8 BOM-s. Notepad++ or Editplus for example. And turn on error reporting by placing at the start of file next clauses: error_reporting(E_ALL); ini_set('display_errors', 1); PHP: This way if header fails, then error is printed to output.
One more thing: Location header should contain absolute URL path. $_SERVER['PHP_SELF'] is relative and that is why it does not work. Yes on some browsers relative location works, but specifications require absolute url.
I'm not a fan of using "exit;". I think programs should be written in a way that the script exits naturally. Calling a termination command can create problems down the road.
Hi All, Thanks to all for the reply messages. I removed the redirection code - header("Location: $ret") and displayed success and error message. That way the client has agreed. Some way we have solved though unable to sort out the bug. Thanks again all of you!