php 中的表单提交值未插入数据库

on form submission values not inserting into database in php

我有一个 html 表单,当用户提交数据时,数据进入数据库,这工作正常,直到我再添加一件事,我添加了邮件功能以在数据完成后发送邮件提交。我的代码如下:

<?php
error_reporting(0);

session_start();
require('db_config.php');

if (isset($_POST['submit'])) {
 
 $name = $_FILES['Photo']['name'];
 list($txt, $ext) = explode(".", $name);
 $image_name = time() . "." . $ext;
 $tmp = $_FILES['Photo']['tmp_name'];
 
 $shame = $_FILES['paymentphoto']['name'];
 list($txts, $exts) = explode(".", $shame);
 $receipt_name = time() . "." . $ext;
 $tmps = $_FILES['paymentphoto']['tmp_name'];
 
 if (move_uploaded_file($tmp, 'uploads/' . $image_name) && move_uploaded_file($tmps, 'receipt/' . $receipt_name)) {
  $sql = "INSERT INTO members (firstname, lastname, image, company, designation, addressone, addresstwo, aadhar, city, state, pin, pan, rnameone, rnametwo, mobile, alternate, email, experience, businessdate, companyregistration, gstin, servicesoffered, fee, mode, receipt) VALUES ('" . $_POST['first_name'] . "','" . $_POST['last_name'] . "' , '" . $image_name . "','" . $_POST['company'] . "', '" . $_POST['designation'] . "','" . $_POST['address'] . "', '" . $_POST['address2'] . "', '" . $_POST['aadhaar'] . "', '" . $_POST['city'] . "', '" . $_POST['state'] . "', '" . $_POST['pin'] . "', '" . $_POST['pan'] . "', '" . $_POST['recommended'] . "', '" . $_POST['recommended2'] . "','" . $_POST['mobile'] . "', '" . $_POST['alternate'] . "', '" . $_POST['email'] . "', '" . $_POST['experience'] . "', '" . $_POST['date'] . "', '" . $_POST['registration'] . "', '" . $_POST['gst'] . "', '" . $_POST['services'] . "', '" . $_POST['fee'] . "', '" . $_POST['payment'] . "', '" . $receipt_name . "' )";
  $mysqli->query($sql);
  
  $to = "teiamembers@gmail.com"; // this is your Email address
  $from = $_POST['email']; // this is the sender's Email address
  $first_name = $_POST['first_name'];
  $last_name = $_POST['last_name'];
  
  $headers = "From:" . $from . "\nMIME-Version: 1.0\nContent-Type: text/html; charset=utf-8\n";
  $headers2 = "From:" . $to;
  $subject = "TEIA Membership Registration Request";
  $subject2 = "TEIA Membership Request";
  $message = $first_name . " has requested for TEIA Registration.  Full Name:" . " " . $first_name . " " . $last_name . "<br>" . "Email:" . $from . "<br>" . "Mobile:" . " " . $_POST['mobile'] . "<br>" . "Company Name:" . " " . $_POST['company'] . "<br>" . "Designation" . " " . $_POST['designation'] . "<br>" . "Residence Address:" . " " . $_POST['address'] . "<br>" . "Office Address:" . " " . $_POST['address2'] . "<br>" . "Aadhaar:" . " " . $_POST['aadhaar'] . "<br>" . "City:" . " " . $_POST['city'] . "<br>" . "State:" . " " . $_POST['state'] . "<br>" . "Pin:" . " " . $_POST['pin'] . "<br>" . "Pan:" . " " . $_POST['pan'] . "<br>" . "Reference:" . " " . $_POST['recommended'] . "<br>" . "Alternate Number:" . " " . $_POST['alternate'] . "<br>" . "Experience:" . " " . $_POST['experience'] . "<br>" . "Aadhaar:" . " " . $_POST['aadhaar'] . "<br>" . "Date of Business Setup:" . " " . $_POST['date'] . "<br>" . "Company Registration Number:" . " " . $_POST['registration'] . "<br>" . "GSTIN:" . " " . $_POST['gst'] . "<br>" . "Services Offered:" . " " . $_POST['services'] . "<br>" . "Fee Paid:" . " " . $_POST['fee'] . "<br>" . "Payment Mode:" . " " . $_POST['payment'] . "<br>";
  $message2 = "Your request for TEIA Membership Received. We will contact you Shortly. ";
  
  mail($to, $subject, $message, $headers);
  mail($from, $subject2, $message2, $headers2); // sends a copy of the message to the sender
  
  if ($mysqli) {
   $msg = "Your Request For Membership Registration Sent Successfully";
  }
 }
}
?>

现在的问题是当用户提交表单时,邮件工作正常,但是值没有进入数据库,谁能告诉我这里可能出了什么问题,在此先感谢

首先注意 SQL 注射。

始终需要进行一些检查。至少……这一个。

if($mysqli->query($sql)) { fine } else { error }

并且在上面的 "error" 部分,如果您提供了错误编号和实际消息,您自己可能已经找到了答案。

我的主要疑问是...您有一些独特的列,但插入并没有像之前出现在数据库中那样发生。

此外,最好使用唯一的 id int auto_increment 用于多种用途。

其次,您应该已经创建了 $mailstatus 并且已经为这条消息检查了相同的而不是 mysqli。

if ($mailstatus) {
    $msg = "Your Request For Membership Registration Sent Successfully";
}