由于更新 mySQL 而无法执行标头位置 - 需要帮助
我有一个可以运行的脚本,但我需要将脚本重定向到成功页面或失败页面。现在,该脚本可以工作,但我仍然停留在 php 脚本中,这是一个空白页面。
任何人都可以看看这个并让我如何解决这个问题吗?
<?PHP
session_start();
?>
<?php
$type=$_POST['type'];
$part_no=$_POST['part_no'];
$description=$_POST['description'];
$count=$_POST['count'];
$min=$_POST['min'];
$max=$_POST['max'];
$db="naturan8_hero";
$link = mysql_connect("localhost", "xxxxxxx", "xxxxxx");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
$query = mysql_query(" UPDATE cartons_current SET type='$type' ,
description='$description',count='$count' , min='$min' , max='$max' WHERE
part_no='$part_no'");
if($query) {
header('Location: success.htm');
}else{
header('Location: fail.htm');
}
?>
I have a script that works, but I need to redirect the script to a success page or fail page. Right now, the script works but I remain stuck in the php script, which is a blank page.
Can anyone take look at this and let me how to fix this?
<?PHP
session_start();
?>
<?php
$type=$_POST['type'];
$part_no=$_POST['part_no'];
$description=$_POST['description'];
$count=$_POST['count'];
$min=$_POST['min'];
$max=$_POST['max'];
$db="naturan8_hero";
$link = mysql_connect("localhost", "xxxxxxx", "xxxxxx");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
$query = mysql_query(" UPDATE cartons_current SET type='$type' ,
description='$description',count='$count' , min='$min' , max='$max' WHERE
part_no='$part_no'");
if($query) {
header('Location: success.htm');
}else{
header('Location: fail.htm');
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
session_start 发送的标头通常是 cookie,可以与位置标头同时发送,没问题
@DaveRandom 评论说, ?> 之间的空格每个 php 文件中的
位置标头也应该有一个绝对 url,
发送标头后退出也是一个好习惯,除非您在重定向后故意运行额外的代码
the header sent by session_start are generally cookies which can be sent at the same time as a location header no problem
@DaveRandom commented, the blank space between the ?> from each php file
the location header should also have an absolute url
it is also good practice to exit after the header is sent, unless you are intentionally running extra code after the redirect