0

I'm creating a website that inserts data into an db. It can pull all the data out of the db with no problem, but somehow it goes wrong when I insert the data.

This is the part that gets the values and make the query and execute the query:

    $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');

The 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;
}

And the error i get:

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', '[email protected]','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)

Data of the table 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;
2
  • Did you check if the write permissions are correct for the .frm file, by your mysql user? Commented Oct 23, 2012 at 6:32
  • @janenz00 I'm using wamp (if that cares), and i can add info in other db's... And i add all permisions to everyone in the list (of the map data in mysql, and the map facilitydb, and add an user everybody with also all permisions, but still no luck... Commented Oct 23, 2012 at 6:39

1 Answer 1

2

Try

REPAIR TABLE facilitydb_main;

Edit INSERT INTO facilitydb_main should be INSERT INTO facilitydb_main (no space)

Sign up to request clarification or add additional context in comments.

8 Comments

When i do that, i get this message back: The storage engine for the table doesn't support repair
Right yes, as it's InnoDB. Try converting to MyISAM "ALTER TABLE facilitydb_main ENGINE=MyISAM;", Repair it and see if the query works?
alright, done that. now the repair says the message ok, but still no luck when executing the query...
the repair didn't output an error, just ok. and still the same error when excecuting the query...
hmmmm.. INSERT INTO ` facilitydb_main` try removing the space.. so INSERT INTO facilitydb_main
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.