0

我正在创建一个将数据插入数据库的网站。它可以毫无问题地将所有数据从数据库中提取出来,但是当我插入数据时它会出错。

这是获取值并进行查询和执行查询的部分:

    $facility_id = $_POST['facilityID'];
    $location_zone_area = $_POST['locationZoneArea'];
    $facility_type = $_POST['facilityType'];
    $structure_type = $_POST['structureType'];
    $material_type = $_POST['materialType'];
    $cause_of_defect = $_POST['causeOfDefect'];
    $defect_outcome = $_POST['defectOutcome'];
    $repair_strategy = $_POST['repairStrategy'];
    $defect_description = $_POST['defectDescription'];
    $defect_condition = $_POST['defectCondition'];
    $likelihood_of_failure = $_POST['likelihoodOfFailure'];
    $consequence_of_failure = $_POST['consequenceOfFailure'];
    $value = $_POST['value'];
    $risk = $_POST['risk'];
    $inspection_frequency = $_POST['inspectionFrequency'];
    $remarks = $_POST['remarks'];
    $structure_plan = $_POST['structurePlan'];
    $name_of_supervisor = $_POST['nameOfSupervisor'];
    $date = $_POST['date'];
    $email = $_POST['email'];

    $sQueryInsertData = "   INSERT INTO `
                            ".DB_PREFIX."main` 
                            (`facility_id`,`location_zone_area`,`structure_type`,`material_type`,`cause_of_defect`,`defect_outcome`,`repair_strategy`,`defect_description`,`defect_condition`,`likelihood_of_failure`,`consequence_of_failure`,`value`,`risk`,`inspection_frequency`,`remarks`,`structure_plan`,`name_of_supervisor`,`date`,`email`,`facility_type`) VALUES ('$facility_id','$location_zone_area','$structure_type','$material_type','$cause_of_defect','$defect_outcome','$repair_strategy','$defect_description','$defect_condition','$likelihood_of_failure','$consequence_of_failure','$value','$risk','$inspection_frequency','$remarks','$structure_plan','$name_of_supervisor','$date', '$email','$facility_type')";
    $insertSuccesfull = do_query($sQueryInsertData,'INSERT');

do_query:

function do_query($le_query_to_execute, $type_to_do) {
    global $link2;
    switch ($type_to_do) {
        case 'SELECT' :
            $return_value = mysqli_query($link2,$le_query_to_execute) or die(mysqlError($le_query_to_execute, mysqli_error($link2)));
            return $return_value;
            break;
        case 'UPDATE' :
            if (mysqli_query($link2,$le_query_to_execute) or die(mysqlError($le_query_to_execute, mysqli_error($link2)))) {
                return TRUE;
            }
            break;
        case 'DELETE' :
            if (mysqli_query($link2,$le_query_to_execute) or die(mysqlError($le_query_to_execute, mysqli_error($link2)))) {
                return TRUE;
            }
            break;
        case 'INSERT' :
            if (mysqli_query($link2,$le_query_to_execute) or die(mysqlError($le_query_to_execute, mysqli_error($link2)))) {
                return TRUE;
            }
            break;
        default :
            mysqlError($le_query_to_execute,'Er is geen keuze gemaakt wat voor soort type query het is.');
            return FALSE;
            break;
    }
    return FALSE;
}

我得到的错误是:

There is an error in the query:

INSERT INTO ` facilitydb_main` (`facility_id`,`location_zone_area`,`structure_type`,`material_type`,`cause_of_defect`,`defect_outcome`,`repair_strategy`,`defect_description`,`defect_condition`,`likelihood_of_failure`,`consequence_of_failure`,`value`,`risk`,`inspection_frequency`,`remarks`,`structure_plan`,`name_of_supervisor`,`date`,`email`,`facility_type`) VALUES ('mcot','nederland / hiero / daar','Administration','Concrete','Low cement content and finely ground cement','Highly permeable concrete','Repair','Defect descri','Lighthouse.jpg','2','1','2','Very Low','Inspection/maintenance in a maximum of 5 years’ time','kaput','Hydrangeas1.jpg','Marc MEesters','now', 'abcdingetje@gmail.com','building')

This is the error mysqli gave: 
Can't find file: '.\facilitydb2test\@000d@000a@0009@0009@0009@0009@0009@0009@0009facilitydb_main.frm' (errno: 22)

表facility_main的数据:

CREATE TABLE `facilitydb_main` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `facility_id` text NOT NULL,
  `location_zone_area` text NOT NULL,
  `structure_type` text NOT NULL,
  `material_type` text NOT NULL,
  `cause_of_defect` text NOT NULL,
  `defect_outcome` text NOT NULL,
  `repair_strategy` text NOT NULL,
  `defect_description` text NOT NULL,
  `defect_condition` text NOT NULL,
  `likelihood_of_failure` int(11) NOT NULL,
  `consequence_of_failure` int(11) NOT NULL,
  `value` int(11) NOT NULL,
  `risk` text NOT NULL,
  `inspection_frequency` text NOT NULL,
  `remarks` text NOT NULL,
  `structure_plan` text NOT NULL,
  `name_of_supervisor` text NOT NULL,
  `date` text NOT NULL,
  `email` text NOT NULL,
  `facility_type` text,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
4

1 回答 1

2

尝试

REPAIR TABLE facilitydb_main;

编辑 INSERT INTOfacilitydb_main应该是 INSERT INTO facilitydb_main(没有空格)

于 2012-10-23T06:35:20.487 回答