PHP 表单未向数据库发送数据
PHP Form Not Sending Data To Database
有人可以帮助我并告诉我为什么我的 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);
}
更改为:
$sql = "INSERT INTO employees (emp_no, birth_date, first_name, last_name, gender, hire_date) VALUES ...
您还可以 return 错误使用:
$result = mysqli_query($conn, $sql) or trigger_error(mysqli_error($conn));
有人可以帮助我并告诉我为什么我的 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);
}
更改为:
$sql = "INSERT INTO employees (emp_no, birth_date, first_name, last_name, gender, hire_date) VALUES ...
您还可以 return 错误使用:
$result = mysqli_query($conn, $sql) or trigger_error(mysqli_error($conn));