From the PHP point of view, MySQL’s datetime type is just a string, so it is OK if you convert the current time to MySQL’s datetime type format using current time with date() and class DateTime.
Here is a solution.
$stmt->bindParam(':created_at',date('Y-m-d H:i:s'), PDO::PARAM_STR);
Connect and write
$last_name = $_POST['last_name']; $first_name = $_POST['first_name']; $flast_name = $_POST['flast_name']; $ffirst_name = $_POST['ffirst_name']; $birth = $_POST['birth']; $mail = $_POST['mail']; $tel = $_POST['tel']; $job_place = $_POST['job-place']; $salary = $_POST['salary']; $filename = $_POST['filename']; $upload = $_POST['upload']; try { $pdo = new PDO('mysql:host=localhost;dbname=engineer;charset=utf8','root','',array(PDO::ATTR_EMULATE_PREPARES => false)); } catch (PDOException $e){ exit('データベース接続失敗'. $e->getMessage()); } $stmt = $pdo -> prepare("INSERT INTO register(last_name, first_name, flast_name, ffirst_name, birth, mail, tel, job_place, salary, filename, upload, created_at) values(:last_name, :first_name, :flast_name, :ffirst_name, :birth, :mail, :tel, :job_place, :salary, :filename, :upload, :created_at)"); $stmt->bindParam(':last_name',$last_name, PDO::PARAM_STR); $stmt->bindParam(':first_name',$first_name, PDO::PARAM_STR); $stmt->bindParam(':flast_name',$flast_name, PDO::PARAM_STR); $stmt->bindParam(':ffirst_name',$ffirst_name, PDO::PARAM_STR); $stmt->bindParam(':birth',$birth, PDO::PARAM_STR); $stmt->bindParam(':mail',$mail, PDO::PARAM_STR); $stmt->bindParam(':tel',$tel, PDO::PARAM_STR); $stmt->bindParam(':job_place',$job_place, PDO::PARAM_STR); $stmt->bindParam(':salary',$salary, PDO::PARAM_INT); $stmt->bindParam(':filename',$filename, PDO::PARAM_STR); $stmt->bindParam(':upload',$upload, PDO::PARAM_STR); $stmt->bindParam(':created_at',date('Y-m-d H:i:s'), PDO::PARAM_STR); $stmt->execute();
mysql> select * from register; +----+-----------+------------+------------+-------------+-------+-------------- ------+---------------+-----------+--------+---------------+-------------------- -----------------+---------------------+ | id | last_name | first_name | flast_name | ffirst_name | birth | mail | tel | job_place | salary | filename | upload | created_at | +----+-----------+------------+------------+-------------+-------+-------------- ------+---------------+-----------+--------+---------------+-------------------- -----------------+---------------------+ | 1 | 田中 | 太郎 | タナカ | タロウ | 1985 | engineer@gmai l.com | 080-1234-5678 | 関東 | 0 | | ./cfile/20190519071 727 | 2019-05-19 07:17:29 | | 2 | 田中 | 太郎 | タナカ | タロウ | 1985 | engineer@gmai l.com | 080-1234-5678 | 関東 | 0 | nightsky.jpeg | ./cfile/20190519071 835nightsky.jpeg | 2019-05-19 07:18:37 | +----+-----------+------------+------------+-------------+-------+-------------- ------+---------------+-----------+--------+---------------+-------------------- -----------------+---------------------+ 2 rows in set (0.00 sec)
Also want to send a email.