标题(“位置:...”);问题 [英] header("Location: ..."); Problem
问题描述
我在尝试运行脚本时收到以下消息:
"警告:无法修改标题信息 - 已经发送的标题(输出
开始于/var/www/html/newcustomer.php:23)
/var/www/html/newcustomer.php第332行"
.... newcustomer.php:23是我的剧本开始的地方,在第23行。
在该行之前,只有评论。
该脚本从表单中恢复数据,检查客户是否存在,如果存在,
它会更新数据,否则会将新客户插入数据库。还有一些
验证在写入数据库之前完成。
提前,感谢您的时间和建议。
FM>
这里是我的剧本流程:
<?php
包含''db.inc''
包含''error.inc。
//初始错误字符串
$ errorString ="" ;;
// clean&修剪张贴值
... ......
//验证数据
if(空($ formvars [" source"]))
$ errorString。=
" \ n< br>您必须提供源名称。 ;;
//验证其他数据
...... ......
//验证结束
//检查是否存在错误
if(!empty($ errorString))
{
//确实存在错误,显示它们&退出
?>
< html>
< body>
< br>错误是找到。
< br>
<?= $ errorString?>
< / body>
< / html>
<?php
退出;
}
//如果所有数据都有效,打开连接并加载到db
if(!(connection = @ .....))
die( ...);
if(!mysql_select_db(...,...))
showerror();
//数据是否正在更新?然后更新数据库
if(!empty($ cust_id))
{
$ query =" UPDATE customer SET" 。
" source = \"" 。 $ formvars [" source"]。 " \"," 。
...... ......
...... ......
WHERE cust_id = $ cust_id" ;;
}
else
//创建查询以插入数据
$ query = INSERT INTO客户
...... ......;
//在客户表上运行查询
>
...... ......
//这是插入吗?
if(empty($ cust_id))< br $>
//找到新客户的cust_id
$ cust_id = mysql_insert_id();
//现在将客户重定向到收据页
header(" Location:cust_receipt.php?cust_id = $ cust_id");
?>
errorString ="" ;;
// clean&修剪张贴值
... ......
//验证数据
if(空(
formvars [" source"]))
errorString。=
" \ n< br>你必须提供来源的名称。;
//验证其他数据
... ......
//验证结束
//检查是否存在错误
if (!空(
I get the following message when trying to run my script:
"Warning: Cannot modify header information - headers already sent by (output
started at /var/www/html/newcustomer.php:23) in
/var/www/html/newcustomer.php on line 332"
....newcustomer.php:23 is where my script begins, at line 23.
before that line, only comments.
The script recives data from a form, checks if the customer exists, if so,
it updates the data otherwise inserts a new customer into the db. Also some
validation is done before writing to the db.
In advance, thanks for your time and advice.
FM>
And here''s the flow of my script:
<?php
include ''db.inc''
include ''error.inc.
//init error string
$errorString = "";
//clean & trim POSTed values
... ... ...
//validate data
if (empty($formvars["source"]))
$errorString .=
"\n<br>You must suply the name of the source.";
//validate other data
... ... ...
//end of validation
//check if errors exist
if (!empty($errorString))
{
//errors do exist, show them & exit
?>
<html>
<body>
<br>Errors were found.
<br>
<?=$errorString?>
</body>
</html>
<?php
exit;
}
//if all data valid, open connection and load into the db
if (!(connection = @ .....))
die( ... );
if (!mysql_select_db( ... , ... ))
showerror();
//Are the data being updated? Then update the database
if (!empty($cust_id))
{
$query = "UPDATE customer SET " .
"source = \"" . $formvars["source"] . "\", " .
... ... ...
... ... ...
WHERE cust_id =$cust_id";
}
else
//Create query to insert the data
$query = INSERT INTO customer
... ... ...";
//Run the query on the customer table
... ... ...
//Is this an insert?
if (empty($cust_id))
//find the cust_id of the new customer
$cust_id = mysql_insert_id();
//Now redirect the customer to the receipt page
header ("Location: cust_receipt.php?cust_id=$cust_id");
?>
errorString = "";
//clean & trim POSTed values
... ... ...
//validate data
if (empty(
formvars["source"]))
errorString .=
"\n<br>You must suply the name of the source.";
//validate other data
... ... ...
//end of validation
//check if errors exist
if (!empty(
这篇关于标题(“位置:...”);问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!