基本上我有一个HTML表单链接到不同位置的php文件以进行操作。目前我正在使用该表单更新用户配置文件,然后将它们发送回editprofile.php。基本上在editprofile.php的顶部,如果他们提交了查询,我想显示“Profile Updated”或“Update to Update”的结果,问题是我无法查询如何在查询时显示查询结果在另一个文件中。
我试图这样做;
<?php
if(!$query)
{
echo '<div class="editfail">Profile failed to update!</div>';
}
else
{
echo '<div class="editsuccess">Profile successfully updated!</div>';
}
?>
除此之外的问题是该查询尚未在此页面上运行,它是从另一个页面运行,然后使用标题重定向回editprofile页面,因此如何显示与上面相同的结果查询是从另一个位置执行的?
答案 0 :(得分:1)
您可以在重定向文件时发送参数。
例如
如果(的mysql_query($ update_query)) {
header('location:editprofile.php?msg="success to save"');
}
else
{
header('location:editprofile.php?msg="failed to save"');
}
甚至你也可以发送旗帜
if(mysql_query($update_query))
{
header('location:editprofile.php?flag=0');
}else
{
header('location:editprofile.php?flag=1');
}
并检查editprofile.php文件中的flag值以显示正确的消息。
答案 1 :(得分:1)
你不应该乱用标题fxn除非你需要 - 取决于output_buffer设置等它们可能会很痛苦:
你可以做你想要的 - 一页一页:
这样的事情 - 作为一个常见的约定,并且在一定程度上,您应该将表单发布到自身 - 您可以将其他页面中的任何其他内容集成到通过/失败配置文件逻辑块中:
<?php
$query = htmlentities($_POST['profiletext']); #sanitize avec tu code du jour
if(!$query || $query != 'someacceptablevalue))
{
#If it's not posted, or its not a good value, tell them it failed
# and redisplay the form to try again
$query_msg = '<div class="editfail">Profile failed to update!</div>';
$profile_form = "<div_class='profile_rest_of_page stuff'>
<form action='#' method='post'>
<input type='text' id='profiletext' name='profiletext/>
</form>
</div>";
}
else
{
# They did it - Success, and link to next step
$query_msg = '<div class="editsuccess">Profile successfully updated!</div>';
$profile_form = 'No form needed - you did it';
}
#One block below handles all in 1 page with above logic:
echo "<body>
<div class='profile_message_container'>
$query_msg
</div>
<div_class='profile_rest_of_page stuff'>
$profile_redo<br/> You did it <a href='next'>next</a>
</div>
</body>
";
?>
答案 2 :(得分:0)
您可以通过两种方式执行此操作:
将查询结果发送到可能被篡改的GET链接中
在包含您的表单的同一页面中处理表单,如下所示
if(isset($_POST['some_name'])) { // Process form } else { // Display form }