繁体   English   中英

更新mySQL结果无法执行标头位置-需要帮助

[英]Unable to execute header location as a result from updating mySQL - Need Assistance

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

?>

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

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

位置标头也应具有绝对网址

<?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;

除非在重定向后有意运行额外的代码,否则最好在发送标头后退出

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2025 STACKOOM.COM