每当我运行此函数(见下文)时,我都会收到错误(请参阅下文)
我反复查看了代码,但找不到此语法错误的原因。
function create($dog){
$details = json_decode($dog, true);
$name = $details['Name'];
$age = $details['Age'];
$breed = $details['Breed'];
$gender = $details['Gender'];
$chip = $details['Chip'];
$vaccine = $details['Vaccine'];
$neutered = $details['Neutered'];
$flea = $details['Flea'];
$health = $details['Health'];
$diet = $details['Diet'];
$behaviour = $details['Behaviour'];
$aggression = $details['Aggression'];
$training = $details['Training'];
$recall = $details['Recall'];
$pull = $details['Pull'];
$offlead = $details['Offlead'];
$vet = $details['Vet'];
$conn = self::connect();
//INSERT Order
$sql = "INSERT INTO dog (`Name`, `Age`, `Gender`, `Breed`, `Neutered`, `Microchip`, `Vaccine`, `Flea`, `Health`, `Diet`, `Behaviour`, `Aggression`, `Training`, `Recall`, `Pull`, `Offlead`, `vetID`)
VALUES ('$name', $age, '$gender', '$breed', $neutered, $chip, $vaccine, $flea, '$health', '$diet', '$behaviour', '$aggression', '$training', '$recall', '$pull', '$offlead', $vet)";
// use exec() because no results are returned
$conn->exec($sql);
}
错误:
Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'n' in 'field list' in C:\xampp\htdocs\classes\DogHandler.php:45 Stack trace: #0 C:\xampp\htdocs\classes\DogHandler.php(45): PDO->exec('INSERT INTO dog...') #1 C:\xampp\htdocs\classes\main.php(29): DogHandler->create('{"Name":"Sparky...') #2 {main} thrown in C:\xampp\htdocs\classes\DogHandler.php on line 45
如果有帮助,这是$dog
参数中的数据:
{"Name":"Sparky",
"Age":8,
"Breed":"Labradoodle",
"Gender":"male",
"Neutered":true,
"Flea":true,
"Vaccine":true,
"Health":"Sore Hips",
"Diet":"No Treats",
"Behaviour":"N/a",
"Aggression":"N/a",
"Training":"Well trained",
"Recall":"Will come back when name called",
"Pull":"Will pull around cats",
"Offlead":"Only in parks",
"Vet":"vet.ID",
"Chip":"n/a"
}