我不知道我做错了什么.它不起作用.
我这么久都很震惊.我无法理解.
$sql="INSERT INTO hr_daily_claim(date,
site,
from,
to,
rental,
vehicle,
claim_id,
parking,
beverages,
others)
VALUES(:date,
:site,
:from,
:to,
:rental,
:vehicle,
:claim_id,
:parking,
:beverages,
:others)";
$stmt = $db->prepare($sql);
$stmt->execute(array(
':date' => $date,
':site' => $site,
':from' => $from,
':to' => $to,
':rental' => $rental,
':vehicle' => $vehicle,
':claim_id' => $cliamId,
':parking' => $parking,
':beverages'=> $beverages,
':others' => $others ));
Run Code Online (Sandbox Code Playgroud)
请有人帮助我.它没有给我任何错误.但受影响的行= 0; 根本不插入.
下面是表格结构
`id` int(11) NOT NULL AUTO_INCREMENT,
`claim_id` varchar(45) DEFAULT NULL,
`date` varchar(10) DEFAULT NULL,
`site` varchar(45) DEFAULT NULL,
`from` varchar(45) DEFAULT NULL,
`to` varchar(45) DEFAULT NULL,
`rental` int(11) DEFAULT NULL,
`vehicle` int(11) DEFAULT NULL,
`parking` int(11) DEFAULT NULL,
`beverages` int(11) DEFAULT NULL,
`others` int(11) DEFAULT NULL,
`timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
Run Code Online (Sandbox Code Playgroud)
from,to是MySQL 中的保留字.你需要用反引号包装它.
$sql="INSERT INTO hr_daily_claim(
`date`,
`site`,
`from`, //<-------- This
`to`, //<-------- This
`rental`,
`vehicle`,
`claim_id`,
`parking`,
`beverages`,
`others`
)
Run Code Online (Sandbox Code Playgroud)
旁注:有可能是在一个错字$cliamId变量':claim_id' => $cliamId,这也许应该理解为':claim_id' => $claimId,,这样做检查,因为这些变量没有在你的问题张贴.
如果一个失败,您的整个查询将失败.需要注意的另一件事是,$claimId并且$claimid不一样.变量区分大小写.