我想通过外部文件log.php.id、mysql DATETIME中的日期集和两个字符串插入数据库。我的函数调用是zapis_log($surename);
。我在prepare
和executing
处得到错误。
log.php
<?php
require 'connect_test.php';
function zapis_log($who) {
$action = "edit";
$log = $conn->prepare("INSERT INTO log (id,date,action,who) VALUES(NULL,NOW(),'$action','$who')");
$insert = $log->execute();
}
?>
谢谢大家。
-
date是关键字。使用反勾号将
date
列括起来 - 不使用
bind_param
更新代码
<?php
require 'connect_test.php';
function zapis_log($who) {
$action = "edit";
$current_date = date("Y-m-d h:i:s");
$log = $conn->prepare("INSERT INTO log (`date`,action,who) VALUES(?,?,?)");
$log->bind_param("sss", $current_date, $action, $who);
$insert = $log->execute();
}
?>