我有以下代码,可以让用户上传文件。这将被写入SQL数据库,然后我希望页面为redirect
。谁能告诉我它为什么不重定向?它完成其他行很好。
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
Choose your file:
<input name="csv" type="file" id="csv"/>
<input type="submit" name="Submit" value="Submit" class="button"/>
</form>
<?php
$connect = mysql_connect("localhost",username,password);
mysql_select_db($database,$connect);
if ($_FILES[csv][size] > 0)
{
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,"r");
while ($data = fgetcsv($handle,1000,",","'"))
{
if ($data[0])
{
$insert_query = "REPLACE INTO `tableNames` SET
`schoolName` = '".$schoolname."',
`teacherName` = '".$data[0]."'
;";
$result = mysql_query($insert_query);
}
}
}
header("Location: https://redirecting address/");
?>
更新
这有效:
....
$result = mysql_query($insert_query);
}
}
}
echo("<script>location.href = 'http"//redirect address';</script>");
?>
答案 0 :(得分:1)
在您输出任何内容之后,您无法发送标题...如果您希望在写入数据后重定向,请将PHP移至脚本顶部。
答案 1 :(得分:0)
答案 2 :(得分:-2)
试试这个:
<?php
$connect = mysql_connect("localhost",username,password);
mysql_select_db($database,$connect);
if ($_FILES[csv][size] > 0)
{
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,"r");
while (!feof($handle))
{
$data = fgetcsv($handle,1000,",","'");
if ($data[0])
{
$insert_query = "REPLACE INTO `tableNames` SET
`schoolName` = '".$schoolname."',
`teacherName` = '".$data[0]."'
;";
$result = mysql_query($insert_query);
}
}
header("Location: https://redirecting address/");
exit;
}
?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
Choose your file:
<input name="csv" type="file" id="csv"/>
<input type="submit" name="Submit" value="Submit" class="button"/>
</form>