I'm trying to get my page to redirect back to another page after the form has been submitted to its self via $_SERVER[PHP_SELF] . I've tried using the header(Location) script but to no avail. Anyone know of an easy way to do this?

Right now.. when my page is submitted all the action and everything is done properly but I'm left with a blank white page.

Here's the code..

Thanks in advance.

<!DOCTYPE html PUBLIC "-//D XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<?php
include('../inc/storeinfo.php');
include('../database.php');

$noteid=$_POST["noteid"];

?>

<head>
<Title><? print $storename?> - <? print $sitename?> - Home</Title>	
<link rel="stylesheet" href="/fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="/fancybox/jquery.fancybox-1.3.4.pack.js"></script>
<link href="../css/viewtickets.css" rel="stylesheet" type="text/css">
</head>
<body>

<div id="editNotesContainer">
	
<?	
$result = mysql_query("SELECT * FROM info WHERE ticket='$noteid'");

while($row = mysql_fetch_array($result))
  {
  echo 	"<div id=\"editNotesHeader\">Editing Notes for Ticket #$noteid</div>" .  	
  		"<div id=\"editNotes\">" .
  		"<form method=\"post\" action=\"$_SERVER[PHP_SELF]\">" . 
  		"<textarea name=\"newnote\" rows=\"10\" cols=\"48\">{$row['notes']}</textarea>" .
  		"<input type=\"hidden\" value=\"$noteid\" name=\"newnoteid\">" .
  		"<br /><input type=\"submit\" value=\"Update\">" .
  		"</form>" .
  		"</div>" ;
  }

if(isset($_POST)){
	$newnote=$_POST["newnote"];		
	$newnoteid=$_POST["newnoteid"];
	mysql_query("UPDATE info SET notes = '$newnote' WHERE ticket = '$newnoteid'");
    echo "testing";
}

?>
</div>
</body>
</html>
<?
mysql_close($con);
?>

where did you put the

header(Location)

? It needs to be before any HTML

Member Avatar for diafol

Just an obs - send forms to different pages, like form handlers, or you'll get trouble when users refresh/reload.

where did you put the

header(Location)

? It needs to be before any HTML

Thing is.. it can't be before my HTML because then the page wont load at all, right? It has to load the page once initially so that the form in it can submit to itself.

Just an obs - send forms to different pages, like form handlers, or you'll get trouble when users refresh/reload.

Thanks for the tip. I'm attempting to make this work so that it cuts down on the pages and code I use, and the amount of redirects. If I can get it to work I'll only have 2 instead of 3.

Thing is.. it can't be before my HTML because then the page wont load at all, right? It has to load the page once initially so that the form in it can submit to itself.

You can make a POSTed variable that checks if the form was submitted (such as a hidden form value) and then submits the form and then put the header(Location) line

basically just put your form submission code at the beginning of the file:

<?php
if(isset($_POST)){
	$newnote=$_POST["newnote"];		
	$newnoteid=$_POST["newnoteid"];
	mysql_query("UPDATE info SET notes = '$newnote' WHERE ticket = '$newnoteid'");
        header(Location)
}
?>

the code will still execute on the server and submit the page, the user doesn't actually have to load the page to submit the form as the php is processed by the server

Problem solved. I ended up placing the code on the top of the page I was trying to redirect to, and removed the header(Location) line. That way my action is set to that page, so I end up there.. and the form is submitted on that page as well.

In a way it's a mixture of burgercho's idea and my own!

Thanks for the help.

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.