我想使用表单将数据插入数据库,但是出现错误。我该怎么解决?
我尝试了几种调试方法,但是没有用。
错误:
注意:第36行的C:\ xampp \ htdocs \ Employ \ index.php中的数组到字符串的转换
代码:
$country = mysqli_real_escape_string($conn, $_POST['country']);
$zip = mysqli_real_escape_string($conn, $_POST['zip']);
$identity =($_FILES['identity']);
$fileName = $_FILES['identity']['name'];
$fileTmpName = $_FILES['identity']['tmp_name'];
$fileSize = $_FILES['identity']['size'];
$fileError = $_FILES['identity']['error'];
$fileType = $_FILES['identity']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allow = array('jpg', 'jpeg', 'png',);
if (in_array($fileActualExt, $allow)) {
if ($fileError === 0) {
if ($fileSize < 1000000) {
$fileNameNew = uniqid('', true) . "." . $fileActualExt;
$fileDestination = 'uploads/' . $fileNameNew;
move_uploaded_file($fileTmpName, $fileDestination);
$sql = "INSERT INTO applicants (name, email, gender, dob, mobile, accounts, occupation, ssn, m_status, address1, address2, city, country, zip, identity) VALUES ('$name', '$email', '$gender', '$dob', '$mobile', '$accounts', '$occupation', '$ssn', '$m_status', '$address1', '$address2', '$city', '$country', '$zip', '$identity')";
$insert = mysqli_query($conn, $sql);
}
}
}
答案 0 :(得分:-1)
错误是由于将$ identity数组用作字符串
$identity =($_FILES['identity']);
$sql = "INSERT INTO applicants (name, email, gender, dob, mobile, accounts, occupation, ssn, m_status, address1, address2, city, country, zip, identity) VALUES ('$name', '$email', '$gender', '$dob', '$mobile', '$accounts', '$occupation', '$ssn', '$m_status', '$address1', '$address2', '$city', '$country', '$zip', '$identity')";
您也可以考虑使用PDO与数据库进行交互。