由于更新 mySQL 而无法执行标头位置 - 需要帮助

发布于 2024-12-10 19:46:28 字数 783 浏览 0 评论 0原文

我有一个可以运行的脚本,但我需要将脚本重定向到成功页面或失败页面。现在,该脚本可以工作,但我仍然停留在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枉心 2024-12-17 19:46:28

session_start 发送的标头通常是 cookie,可以与位置标头同时发送,没问题

@DaveRandom 评论说, ?> 之间的空格每个 php 文件中的

位置标头也应该有一个绝对 url,

<?PHP
session_start();

$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: http://www.mysite.com/success.htm');
}else{
    header('Location: http://www.mysite.com/fail.htm');
}
exit;

发送标头后退出也是一个好习惯,除非您在重定向后故意运行额外的代码

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

<?PHP
session_start();

$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: http://www.mysite.com/success.htm');
}else{
    header('Location: http://www.mysite.com/fail.htm');
}
exit;

it is also good practice to exit after the header is sent, unless you are intentionally running extra code after the redirect

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文