调用非对象mysqli上的成员函数bind_param()


call to a member function bind_param() on a non-object mysqli

提交表单时出现此错误。对非对象的成员函数bind_param()的调用我也检查了控制台。它显示了我在表单中输入的所有值。这些值存储在json变量中并传递到php页面。它在bind_param()函数上,它显示了错误。同样的代码适用于我项目的其余两页,但不适用于这一页。请帮助

以下是PHP代码

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "kites";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
    alert("Connection failed");
}
else
{
// Check for empty fields
  if(
        empty($_POST['username']) || empty($_POST['password']) || empty($_POST['firstname']) || empty($_POST['lastname']) || empty($_POST['age']) || empty($_POST['contact']) || empty($_POST['streetname']) || empty($_POST['buildingname']) || empty($_POST['landmark']) || empty($_POST['area']) || empty($_POST['pincode']) || empty($_POST['email']) || empty($_POST['univ']) || empty($_POST['qualification']) || empty($_POST['dialcode']) || empty($_POST['countrycode']) || empty($_POST['bloodgroup']) || empty($_POST['school'])  
     )
  {  
  echo json_encode(array('status'=>false,'msg'=>'No arguments provided'));
  }
  else if(is_numeric($_POST['firstname']) && is_numeric($_POST['lastname']))
  {
    echo json_encode(array('status'=>false,'msg'=>'Name should not contain numbers. Please try again'));
  }
  else if(!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
  {
    echo json_encode(array('status'=>false,'msg'=>'Check your email id and try again'));
  }
  else if(!is_numeric($_POST['age']))
  {
    echo json_encode(array('status'=>false,'msg'=>'Age should contain only numbers'));
  }
  else{
         $username = $_POST['username'];
         $password = $_POST['password'];
         $firstname = $_POST['firstname'];
         $lastname = $_POST['lastname'];
         $age = $_POST['age'];
         $bloodgroup = $_POST['bloodgroup'];
         $contact = $_POST['contact'];
         $streetname = $_POST['streetname'];
         $buildingname = $_POST['buildingname'];
         $landmark = $_POST['landmark'];
         $area = $_POST['area'];
         $pincode = $_POST['pincode'];
         $email = $_POST['email'];
         $univ = $_POST['univ'];
         $school = $_POST['school'];
         $qualification = $_POST['qualification'];
         $dialcode = $_POST['dialcode'];
         $countrycode = $_POST['countrycode'];
        // $sql = "INSERT INTO join_form (name,email,contact,role,dialcode,countrycode) VALUES ('$name','$email','$contact','$role','$dialcode','$countrycode')";
         $stmt = $conn->prepare("INSERT INTO register_form(username,password,firstname,lastname,age,bloodgroup,contact,streetname,buildingname,landmark,area,pincode,email,univ,school,qualification,dialcode,countrycode) VALUES(?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?)");
        $stmt->bind_param("ssssisssssssssssss",$username,$password,$firstname,$lastname,$age,$bloodgroup,$contact,$streetname,$buildingname,$landmark,$area,$pincode,$email,$univ,$school,$qualification,$dialcode,$countrycode);
        $sql = $stmt->execute();
        if ($sql) {
          echo json_encode(array('status'=>true,'msg'=>"New record created successfully"));
       //   // Create the email and send the message
       // $to = 'naitikgada1995@gmail.com'; // Add your email address inbetween the '' replacing yourname@yourdomain.com - This is where the form will send a message to.
       // $email_subject = "Registration Successfull:  $name";
       // $email_body = "We have sent this mail to inform you that your registration is successfull'n'n"
       //                ."Here are the details:'n'n"
       //                ."Name: $name'n'nEmail: $email'n'nContact:$contact'n'nPassword: $password'n'n";
       // $headers = "From: noreply@kiddo.com'n";
       // $headers .= "Reply-To: $email";  
       // mail($to,$email_subject,$email_body,$headers);
       // // $response['status'] = 'true';
        } 
        else {    
          echo json_encode(array('status'=>false,'msg'=>'Enter different email id or contact number and try again'));
        // return false;
        // $response['feedback'] = 'false';
        // $response['message'] = 'Sorry, something went wrong. Please try again. Try entering a different email id and contact number';
        // echo "Error: " . $sql . "<br>" . mysqli_error($conn);
      }
    // header("Content-Type: application/json; charset=utf-8", true);

  }
}     
?>

查看查询中此行是否存在拼写错误或任何其他错误

         $stmt = $conn->prepare("INSERT INTO register_form(username,password,firstname,lastname,age,bloodgroup,contact,streetname,buildingname,landmark,area,pincode,email,univ,school,qualification,dialcode,countrycode) VALUES(?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?,?, ?, ?, ?, ?, ?)");