简体   繁体   中英

PHP Internal Server Error 500, Javascript call to PHP gives error

I have a javascript function save_edit_tract that calls the php file UpdateTract. Whenever it runs either Update Tract or Add Tract I get a 500 error. I've played around with debugging and it says seems that the data isn't getting pushed to the server. I feel like I'm missing something in the php?

save_edit_tract function in Javascript:

        $scope.save_edit_tract= function(){
            ...
            $.ajax({
                url: php_url,
                method: 'POST',
                dataType: 'json',
                data:{
                    tract_id:$scope.tract.id,
                    tract_name:$scope.tract.tract_name_edit,
                    alias:$scope.tract.alias_edit,
                    nature_reserve:nature_reserves_string,
                    acquisition_date:$scope.tract.acquisition_date_edit,
                    acquisition_type:acquisition_type_string,
                    tract_size_acres:$scope.tract.tract_size_acres_edit,
                    tract_size_hectares:$scope.tract.tract_size_hectares_edit,
                    conservation_agreement:conservation_agreement_string,
                    tax_program:tax_program_string,
                    concession_number:$scope.tract.concession_number_edit,
                    township:$scope.tract.township_edit,
                    assessment_number:$scope.tract.assessment_number_edit,
                    their_lawyer:$scope.tract.their_lawyer_edit,
                    our_lawyer:$scope.tract.our_lawyer_edit,
                    previous_owner:$scope.tract.previous_owner_edit,
                    legal_description:$scope.tract.legal_description_edit
                },
                success: function(data){
                        $scope.clear_tract();
                    }
                    $scope.applyScope();
                },
                error:function (){
                    alert("Apologies that the database is having troubles.");
                }
            });
        }

UpdateTract file in PHP:

<?php
$returnInfo = array();
$returnInfo["sql"] = "";
$returnInfo["error"] = "none";
$returnInfo["insert_id"] = "-1";
$returnInfo["results"] =  array();

$tract_id = $_POST['tract_id'];
$tract_name = $_POST['tract_name'];
$alias = $_POST['alias'];
$nature_reserve = $_POST['nature_reserve'];
$acquisition_date = $_POST['acquisition_date'];
$acquisition_type = $_POST['acquisition_type'];
$tract_size_acres = $_POST['tract_size_acres'];
$tract_size_hectares = $_POST['tract_size_hectares'];
$conservation_agreement = $_POST['conservation_agreement'];
$tax_program = $_POST['tax_program'];
$township = $_POST['township'];
$concession_number = $_POST['concession_number'];
$assessment_number = $_POST['assessment_number'];
$our_lawyer = $_POST['our_lawyer'];
$their_lawyer = $_POST['their_lawyer'];
$previous_owner = $_POST['previous_owner'];
$legal_description = $_POST['legal_description'];

include_once("ConfigKeyCodes.php");
$conn = new mysqli(NR_HOSTNAME, NR_USERNAME, NR_PASSWORD, NR_DATABASE);
// Check connection
if (mysqli_connect_errno()){
    $returnInfo["error"] = "Failed to connect to MySQL";
    printf(json_encode($returnInfo));
    return;
}

$sql = "UPDATE tract_info SET tract_name = ?, nature_reserve = ?, alias = ?, acquisition_date = ?, acquisition_type = ?, tract_size_acres = ?, tract_size_hectares = ?, conservation_agreement = ?, tax_program = ?, township = ?, concession_number = ?, assessment_number = ?, our_lawyer = ?, their_lawyer = ?, previous_owner = ?, legal_description = ?, WHERE tract_id = ?";

$returnInfo["sql"] =$sql;
$query = $conn->prepare($sql);

$query->bind_param("ssssssssssssssssi",$tract_name,$nature_reserve,$alias,$acquisition_date,$acquisition_type, $tract_size_acres,$tract_size_hectares,$conservation_agreement,$tax_program,$township,$concession_number,$assessment_number,$our_lawyer,$their_lawyer,$previous_owner,$legal_description, $tract_id);

if($query->execute()){
$returnInfo["success"] = true;
}$conn->close();

print_r(json_encode($returnInfo));
?>

 $scope.save_edit_tract = function() { ... $.ajax({ url: php_url, type: 'POST', dataType: 'json', data: { tract_id: $scope.tract.id, tract_name: $scope.tract.tract_name_edit, alias: $scope.tract.alias_edit, nature_reserve: nature_reserves_string, acquisition_date: $scope.tract.acquisition_date_edit, acquisition_type: acquisition_type_string, tract_size_acres: $scope.tract.tract_size_acres_edit, tract_size_hectares: $scope.tract.tract_size_hectares_edit, conservation_agreement: conservation_agreement_string, tax_program: tax_program_string, concession_number: $scope.tract.concession_number_edit, township: $scope.tract.township_edit, assessment_number: $scope.tract.assessment_number_edit, their_lawyer: $scope.tract.their_lawyer_edit, our_lawyer: $scope.tract.our_lawyer_edit, previous_owner: $scope.tract.previous_owner_edit, legal_description: $scope.tract.legal_description_edit }, success: function(data) { $scope.clear_tract(); } $scope.applyScope(); }, error: function() { alert("Apologies that the database is having troubles."); } }); }

there is a Programming error , do type: 'POST' instead of method: 'POST'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM