在下面的代码中,我尝试在将值写入数据库后重定向页面。但是一旦写入数据,页面就不会被重定向
代码是
IMPORT EMPLOYEE DETAILS
</h2>
<br><br>
<form method="post" action="import.php" enctype="multipart/form-data">
<!-- <input type="text" name="excelname"> -->
Please Choose your excel(in .xls format): <input type="file" name="file" id="file" class="multifile">
DATE: <input type="date" name="period" id="date" value="">
<input type="submit" value="IMPORT" name="submit" class="button">
</form>
<?php
if($_POST["period"])
{
$Date=$_POST["period"];
$sql1="INSERT INTO report (report_date) VALUES ('$Date') ";
mysqli_query($connection,$sql1);
}
$Date=NULL;
$excel = new Spreadsheet_Excel_Reader();
if(isset($_POST['submit'])){
$name=$_FILES["file"]["name"];
move_uploaded_file($_FILES["file"]["tmp_name"],
"excel/" . $_FILES["file"]["name"]);
$upload_name='excel/'.$name;
echo'<br>';
if($name != null)
{
$excel->read($upload_name);
$x=1;
while($x<=$excel->sheets[0]['numRows']) {
echo "\t<tr>\n";
$y=1;
$index=0;
$arr = array();
while($y<=$excel->sheets[0]['numCols']) {
$cell = isset($excel->sheets[0]['cells'][$x][$y]) ? $excel->sheets[0]['cells'][$x][$y] : '';
//echo "\t\t<td>$cell</td>\n";
if($x>1)
{
$arr[$index]=$cell;
$index++;
}
$y++;
}
if(!empty($arr))
{
if(!empty($n1))
{
$n1=null;
}
else {
$sql="INSERT INTO emp_csv (search_parameters,empty,report_type,operation,web_rep_no,test_performed_by,sales_person,region,customer,distributor,report_group,test_date,date,part,operation_type,material_designation,material_group,conditions,comments,savings,number_1,number_2,approved_report,flag,cases,tool_body,main_insert,grade,manufacturer,d,vc,n,f_fz,l,ap,ae,coolant,mach_power_reqt,edge,performance,cost,saving_per_annum,hardness,type_of_cut,flank_wear,finish,primary_failure_mode,chip_shape,reason_for_index,r_id) VALUES ('$arr[0]','$arr[1]','$arr[2]','$arr[3]','$arr[4]','$arr[5]','$arr[6]','$arr[7]','$arr[8]','$arr[9]','$arr[10]','$arr[11]','$arr[12]','$arr[13]','$arr[14]','$arr[15]','$arr[16]','$arr[17]','$arr[18]','$arr[19]','$arr[20]','$arr[21]','$arr[22]','$arr[23]','$arr[24]','$arr[25]','$arr[26]','$arr[27]','$arr[28]','$arr[29]','$arr[30]','$arr[31]','$arr[32]','$arr[33]','$arr[34]','$arr[35]','$arr[36]','$arr[37]','$arr[38]','$arr[39]','$arr[40]','$arr[41]','$arr[42]','$arr[43]','$arr[44]','$arr[45]','$arr[46]','$arr[47]','$arr[48]',(SELECT MAX( report_id ) FROM report))";
mysqli_query($connection,$sql);
}
$result=mysql_query($sql);
mysql_close();
}
echo "\t</tr>\n";
$x++;
}
header('Location: http://localhost/kmtcrg/confirm.php');
}
}
?>
任何人都可以帮助我,我没有在这个
中出错答案 0 :(得分:0)
之前标题不能是任何输出。
将PHP脚本移到HTML上方。
<?php
// your code
header();
?>
Your HTML
答案 1 :(得分:0)
您需要使用ob_start
read about ob_start
并将你的PHP代码移到顶部,如黑豹建议的那样。所以你的代码看起来更像是
<?php
ob_start(); //using ob_start is a good practice
// your code
header();
?>
Your HTML