PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
hi to everybody
i wrote a simple code for a quest book. it shows the 8/1page messages and at the bottom a form to write the new message. the problem is this;
when somebody writes a new message and it appears on mysite.com/page.php?page=1
and then if the user wants to refresh the page this warning appears;
confirm
the page you are trying to view contains POST DATA. if you resend the data any action the form carried out will be repeated
i controlled it by a if condition not to write the same data. but still this warning appears.
how can i control these not to resend the same data when it is refreshed. for example i see that non forums behaves like this. you submit your message, and refresh several times but there is no warning or problem.
i am sorry but i did not understand well , may be because of my poor english. if you explain it for me i will be happy. a small reminder;
the user writes a new message and it appears on .mysite.com/mes.php?page=1
the user refreshes a warning appears. i want this;
when user refreshes none warning appears
thank again
i tried it in localhost
for the first page it is shown on ..index1.php
the code is
if($user!=NULL && $message!=NULL)
{
$query = "INSERT INTO forum1 VALUES('', '".$user."', '".$date."', '".$time."', '".$message."')";
$result1 = mysql_query($query) or die('yazida bir hata oldu, ayni mesaji tekrarlamis olabilirsiniz');
header("Location: index1.php");
}
but it gives this error when the message is submitted
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\projeler\ziyaretci defteri\index1.php:11) in C:\wamp\www\projeler\ziyaretci defteri\index1.php on line 60
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
[quote="Burrito"]you can't output anything (even whitespace) above your call to the [url=http://php.net/function.header]header()[/url] function.[/quote]
may be, i am wasting your time but i did not understand really
[quote]..and use a full url, no half-assing [/quote]
i did it like this;
if($user!=NULL && $message!=NULL)
{
$query = "INSERT INTO forum1 VALUES('', '".$user."', '".$date."', '".$time."', '".$message."')";
$result1 = mysql_query($query) or die('there is a fault');
header("Location: http://localhost/projeler/ziyaretci_defteri/index1.php");
}
but still gives this error
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\projeler\ziyaretci_defteri\index1.php:11) in C:\wamp\www\projeler\ziyaretci_defteri\index1.php on line 62
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
i hope i don't waste your time but still i have not solved my problem. i read the php.net and i saw a warning below;
Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.
as i understand; if there is a form to send an output to the page, the header function gives error. so, it gives when i browse. and i put it in the code, which a form exists. is it the problem, did i understand correct and how can i solve my problem?
<------- there is a blank line at the very top of the script, this outputs to the browser, so headers
already sent
<?php
header("location: index.php);
?>
<?php
$Query = "INSERT INTO blah blah";
$Result = mysql_query($Query);
//do other processing that does not involve writing output to the browser
header("location: index.php");
?>
So in short no text whatsoever can be sent to the browser before calling the header("location: index.php").
thanks for your explanations with examples.
so, i can't put header() into my code, because there are html tags, and other output keys like echo .
i think i have to find a new solution which i write about it above