【发布时间】:2018-07-26 15:46:53
【问题描述】:
有人可以帮助我并告诉我为什么我的 php 表单没有将数据发送到数据库。
类型为emp_no(int11)、birth_date(date)、first_name(varchar14)、last_name(varchar16)、gender(enum('M','F')、hire_date(date)
// Checks to see if the save button was pressed and if so, then it should run the
query that inserts the data into the data fields specified.
if(isset($_POST['save'])) {
$sql = "INSERT INTO 'employees' ('emp_no', 'birth_date', 'first_name',
'last_name', 'gender', 'hire_date')
VALUES ('".$_POST['emp_no']."', '".$_POST['birth_date']."',
'".$_POST['first_name']."', '".$_POST['last_name']."',
'".$_POST['gender']."', '".$_POST['hire_date']."')";
$result = mysqli_query($conn, $sql);
}
【问题讨论】:
-
使用 print_r($_POST) 并将结果发送给我们
-
你不应该用
'包裹列/表名,而是使用反引号..` -
代码易受 sql 注入攻击。切换到prepared statments,保护您自己和您的用户
-
@Tom Array ( [emp_no] => 29302 [birth_date] => 2018-05-26 [first_name] => Matthew [last_name] => Blackert [gender] => M [hire_date] = > 2018-06-26 [保存] => 输入员工信息)
标签: php mysql backend web-development-server