你好,大家好。
我要问一个愚蠢的问题,但是我找不到错误的原因,这就是为什么它使我沮丧了一个星期。我有一个包含100个输入的表单。输入表单没有太多问题,但是php方面是我遇到的问题。
我的php代码看起来不错,但是在提交时,仅回显“错误”,而不是在发生错误时将我重定向回表单页面。谁能告诉我我的php代码做错了什么?
addreport.php
<?php
session_start();
if(empty($_SESSION['user'])){
header ("Location:../index.php");
}
require_once("../db.php");
if(isset($_POST)){
$stmt = $conn->prepare("INSERT INTO iir_incidentmain(user_id, incident_title, incident_description, witness, incident_date, incident_year, incident_month, monsoon, holiday, incident_time, time_hourly, time_category,
project_facility_logistic, country, state, onshoreoffshore, incident_location, incident_worksite, vessel, incident_type, incident_category, accident_type, day_lost_time, estimated_cost, actual_cost, spill_voll,
production_loss, production_unit, downtime, impact_to, division, department, business_group, business_section, opus, domestic_international, project_name, section, project_phase, project_start_date, project_end_date ,
contractor, sub_contractor, name, nationality, age_number, age_range, gender, work_trade, years_of_experience, imm_supervisor_name, desc_of_injury, body_part, body_part_group, hours_in_shift, days_in_tour, hse_risk,
critical_activity, sub_critical, hazard, hazard_number, sub_hazard, sub_hazard_no, failed_missing_barrier, ic_description1, precondition1, uauc1, ic_description2, precondition2, uauc2, ic_description3, precondition3,
uauc3, ic_description4, precondition4, uauc4, root_cause_latern_failure1, root_cause_latern_failure2, root_cause_latern_failure3, root_cause_latern_failure4, brf1, brf2, brf3, brf4, latitude, longitude,
immediateaction, person_responsible, completion_date, permanentaction, person_responsible1, completion_date1, managementaction, person_responsible2, completion_date2, ratingperson, ratingenvironment, ratingasset,
ratingreputation, ratingsecurity, report_status, file)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
$stmt->bind_param("isssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss", $_SESSION['id'], $incident_title, $incident_description, $witness, $incident_date, $incident_year,
$incident_month, $monsoon, $holiday, $incident_time, $time_hourly, $time_category, $project_facility_logistic, $country, $state, $onshoreoffshore, $incident_location, $incident_worksite, $vessel, $incident_type,
$incident_category, $accident_type, $day_lost_time, $estimated_cost, $actual_cost, $spill_voll, $production_loss, $production_unit, $downtime, $impact_to, $division, $department, $business_group, $business_section,
$opus, $domestic_international, $project_name, $section, $project_phase, $project_start_date, $project_end_date , $contractor, $sub_contractor, $name, $nationality, $age_number, $age_range, $gender, $work_trade,
$years_of_experience, $imm_supervisor_name, $desc_of_injury, $body_part, $body_part_group, $hours_in_shift, $days_in_tour, $hse_risk, $critical_activity, $sub_critical, $hazard, $hazard_number,
$sub_hazard, $sub_hazard_no, $failed_missing_barrier, $ic_description1, $precondition1, $uauc1, $ic_description2, $precondition2, $uauc2, $ic_description3, $precondition3, $uauc3, $ic_description4,
$precondition4, $uauc4, $root_cause_latern_failure1, $root_cause_latern_failure2, $root_cause_latern_failure3, $root_cause_latern_failure4, $brf1, $brf2, $brf3, $brf4, $latitude, $longitude, $immediateaction,
$person_responsible, $completion_date, $permanentaction, $person_responsible1, $completion_date1, $managementaction, $person_responsible2, $completion_date2, $ratingperson, $ratingenvironment, $ratingasset,
$ratingreputation, $ratingsecurity, $report_status, $file);
$incident_title = mysqli_real_escape_string($conn, $_POST['incident_title']);
$incident_description = mysqli_real_escape_string($conn, $_POST['incident_description']);
$witness = mysqli_real_escape_string($conn, $_POST['witness']);
$incident_date = mysqli_real_escape_string($conn, $_POST['incident_date']);
$incident_year = mysqli_real_escape_string($conn, $_POST['incident_year']);
$incident_month = mysqli_real_escape_string($conn, $_POST['incident_month']);
$monsoon = mysqli_real_escape_string($conn, $_POST['monsoon']);
$incident_time = mysqli_real_escape_string($conn, $_POST['incident_time']);
$time_hourly = mysqli_real_escape_string($conn, $_POST['time_hourly']);
$time_category = mysqli_real_escape_string($conn, $_POST['time_category']);
$holiday = mysqli_real_escape_string($conn, $_POST['holiday']);
$incident_location = mysqli_real_escape_string($conn, $_POST['incident_location']);
$latitude = mysqli_real_escape_string($conn, $_POST['latitude']);
$longitude = mysqli_real_escape_string($conn, $_POST['longitude']);
$incident_worksite = mysqli_real_escape_string($conn, $_POST['incident_worksite']);
$onshoreoffshore = mysqli_real_escape_string($conn, $_POST['onshoreoffshore']);
$sector = mysqli_real_escape_string($conn, $_POST['sector']);
$department = mysqli_real_escape_string($conn, $_POST['department']);
$business_group = mysqli_real_escape_string($conn, $_POST['business_group']);
$business_section = mysqli_real_escape_string($conn, $_POST['business_section']);
$country = mysqli_real_escape_string($conn, $_POST['country']);
$state = mysqli_real_escape_string($conn, $_POST['state']);
$opus = mysqli_real_escape_string($conn, $_POST['opus']);
$vessel = mysqli_real_escape_string($conn, $_POST['vessel']);
$project_name = mysqli_real_escape_string($conn, $_POST['project_name']);
$project_type = mysqli_real_escape_string($conn, $_POST['project_type']);
$project_phase = mysqli_real_escape_string($conn, $_POST['project_phase']);
$project_start_date = mysqli_real_escape_string($conn, $_POST['project_start_date']);
$project_end_date= mysqli_real_escape_string($conn, $_POST['project_end_date']);
if($_POST['contractor']=="ifothers")
{
$contractor = mysqli_real_escape_string($conn, $_POST['contractor2']);
}
else
{
$contractor = mysqli_real_escape_string($conn, $_POST['contractor']);
}
$sub_contractor = mysqli_real_escape_string($conn, $_POST['sub_contractor']);
$incident_type = mysqli_real_escape_string($conn, $_POST['incident_type']);
$incident_category = mysqli_real_escape_string($conn, $_POST['incident_category']);
$accident_type = mysqli_real_escape_string($conn, $_POST['accident_type']);
$name = mysqli_real_escape_string($conn, $_POST['injuriousname']);
$nationality = mysqli_real_escape_string($conn, $_POST['nationality']);
$age_number = mysqli_real_escape_string($conn, $_POST['age']);
$age_range = mysqli_real_escape_string($conn, $_POST['agerange']);
$gender = mysqli_real_escape_string($conn, $_POST['gender']);
$work_trade = mysqli_real_escape_string($conn, $_POST['worktrades']);
$years_of_experience = mysqli_real_escape_string($conn, $_POST['yearsexp']);
$imm_supervisor_name = mysqli_real_escape_string($conn, $_POST['supervisor']);
$desc_of_injury = mysqli_real_escape_string($conn, $_POST['injuries_description']);
$body_part = mysqli_real_escape_string($conn, $_POST['bodypart']);
$body_part_group = mysqli_real_escape_string($conn, $_POST['bodypartgroup']);
$hours_in_shift = mysqli_real_escape_string($conn, $_POST['hoursinshift']);
$days_in_tour = mysqli_real_escape_string($conn, $_POST['daysintour']);
$day_lost_time = mysqli_real_escape_string($conn, $_POST['daylosttime']);
$estimated_cost = mysqli_real_escape_string($conn, $_POST['estimatedcost']);
$actual_cost = mysqli_real_escape_string($conn, $_POST['actualcost']);
$spill_vol = mysqli_real_escape_string($conn, $_POST['spillvolume']);
$production_loss = mysqli_real_escape_string($conn, $_POST['productionloss']);
if($_POST['productionunit']=="OTHER")
{
$production_unit = mysqli_real_escape_string($conn, $_POST['productionunit2a']);
}
else
{
$production_unit = mysqli_real_escape_string($conn, $_POST['productionunit']);
}
$downtime = mysqli_real_escape_string($conn, $_POST['downtime']);
$impact_to = mysqli_real_escape_string($conn, $_POST['impactto']);
$hse_risk = mysqli_real_escape_string($conn, $_POST['hserisks']);
$critical_activity = mysqli_real_escape_string($conn, $_POST['critical_activity']);
$sub_critical = mysqli_real_escape_string($conn, $_POST['sub_activity']);
$hazard = mysqli_real_escape_string($conn, $_POST['hazard']);
$hazard_number = mysqli_real_escape_string($conn, $_POST['hazardnumber']);
$sub_hazard = mysqli_real_escape_string($conn, $_POST['subhazard']);
$sub_hazard_no = mysqli_real_escape_string($conn, $_POST['subhazardnumber']);
$failed_missing_barrier = mysqli_real_escape_string($conn, $_POST['barrier']);
$ic_description1 = mysqli_real_escape_string($conn, $_POST['ic_description1']);
$precondition1 = mysqli_real_escape_string($conn, $_POST['precondition1']);
$uauc1 = mysqli_real_escape_string($conn, $_POST['uauc1']);
$root_cause_latern_failure1 = mysqli_real_escape_string($conn, $_POST['ic_description1']);
$brf1 = mysqli_real_escape_string($conn, $_POST['riskfactor1']);
$ic_description2 = mysqli_real_escape_string($conn, $_POST['ic_description2']);
$precondition2 = mysqli_real_escape_string($conn, $_POST['precondition2']);
$uauc2 = mysqli_real_escape_string($conn, $_POST['uauc2']);
$root_cause_latern_failure2 = mysqli_real_escape_string($conn, $_POST['ic_description2']);
$brf2 = mysqli_real_escape_string($conn, $_POST['riskfactor2']);
$ic_description3 = mysqli_real_escape_string($conn, $_POST['ic_description3']);
$precondition3 = mysqli_real_escape_string($conn, $_POST['precondition3']);
$uauc3 = mysqli_real_escape_string($conn, $_POST['uauc3']);
$root_cause_latern_failure3 = mysqli_real_escape_string($conn, $_POST['ic_description3']);
$brf3 = mysqli_real_escape_string($conn, $_POST['riskfactor3']);
$ic_description4 = mysqli_real_escape_string($conn, $_POST['ic_description4']);
$precondition4 = mysqli_real_escape_string($conn, $_POST['precondition4']);
$uauc4 = mysqli_real_escape_string($conn, $_POST['uauc4']);
$root_cause_latern_failure4 = mysqli_real_escape_string($conn, $_POST['ic_description4']);
$brf4 = mysqli_real_escape_string($conn, $_POST['riskfactor4']);
$immediateaction = mysqli_real_escape_string($conn, $_POST['immediateaction']);
$person_responsible = mysqli_real_escape_string($conn, $_POST['person_responsible']);
$completion_date = mysqli_real_escape_string($conn, $_POST['completion_date']);
$permanentaction = mysqli_real_escape_string($conn, $_POST['permanentaction']);
$person_responsible1 = mysqli_real_escape_string($conn, $_POST['person_responsible1']);
$completion_date1 = mysqli_real_escape_string($conn, $_POST['completion_date1']);
$managementaction = mysqli_real_escape_string($conn, $_POST['managementaction']);
$person_responsible1 = mysqli_real_escape_string($conn, $_POST['person_responsible2']);
$completion_date2 = mysqli_real_escape_string($conn, $_POST['completion_date2']);
$ratingperson = mysqli_real_escape_string($conn, $_POST['ratingperson']);
$ratingenvironment = mysqli_real_escape_string($conn, $_POST['ratingenvironment']);
$ratingasset = mysqli_real_escape_string($conn, $_POST['ratingasset']);
$ratingreputation = mysqli_real_escape_string($conn, $_POST['ratingreputation']);
$ratingsecurity = mysqli_real_escape_string($conn, $_POST['ratingsecurity']);
$report_status = mysqli_real_escape_string($conn, $_POST['report_status']);
$total = count($_FILES['file']['name']);
for( $i=0 ; $i < $total ; $i++ ){
$tmpFilePath = $_FILES['file']['tmp_name'][$i];
if ($tmpFilePath != ""){
$newFilePath = "../uploads/attachment" . $_FILES['file']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
echo "Uploads success";
} else {
echo "Failed to upload";
header ("Location: newentry.php");
exit();
}
}
}
if ($stmt->execute()){
$_SESSION ['reportSuccess']= true;
header("Location: index.php");
exit();
} else {
echo "Error";
}
$stmt->close();
}else
header ("Location: newentry.php");
exit();
?>
点击“提交”按钮后结果如何