Я застрял здесь: фатальная ошибка: вызов функции-члена prepare () для null в C: \ wamp64 \ www\covid19-rdc \ wp-content \ plugins \ cov19-dr c -form \ inclus \ cdf -functions. php в строке 431.
Я создаю плагин для WordPress, который содержит регистрационную форму. Но, пытаясь вставить данные через мой плагин, я получаю это сообщение. Я читал подобные проблемы в Интернете, но ни один из них не близок к моему делу. От меня к nez php, поэтому, пожалуйста, помогите.
Вот мое соединение:
require_once plugin_dir_path(__FILE__) . 'cnx_bdd.php';
А остальная часть кода здесь ниже:
//Connexion to the db in the connexion file
$host = "localhost";
$db = "covid19rdc_db";
$user = "root";
$pass = "";
$charset = "utf8mb4";
try
{
$pdo = new PDO("mysql:host=$host;dbname=$db;charset=$charset", $user, $pass);
}
catch (\PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
}
// Это функция, которая сохраняет данные
function save_data()
{
if ( isset($_POST['btnEnregistrer'] ) )
{
// sanitize entries
global $nomPat, $postnomPat, $prenomPat, $datenaisPat, $sexePat, $etatcivil, $nationalite_ID, $telPat, $emailPat, $domicilePat, $commune_ID, $ville, $paysvisites, $date_entree, $point_entree, $contactUrgence, $emailUrgence, $telUrgence, $catdeclarant, $fonction_agent, $commentaires;
$nomPat = sanitize_text_field( $_POST['nomPat'] );
$postnomPat = sanitize_text_field( $_POST['postnomPat'] );
$prenomPat = sanitize_text_field( $_POST['prenomPat'] );
$datenaisPat = $_POST['datenaisPat'];
$sexePat = $_POST['sexePat'];
$etatcivil = $_POST['etatcivil'];
$nationalite_ID = $_POST['nationalite_ID'];
$telPat = sanitize_text_field( $_POST['telPat'] );
$emailPat = sanitize_email( $_POST['emailPat'] );
$domicilePat = sanitize_text_field( $_POST['domicilePat'] );
$commune_ID = $_POST['commune_ID'];
$ville = sanitize_text_field( $_POST['ville'] );
$paysvisites = sanitize_text_field( $_POST['paysvisites'] );
$date_entree = $_POST['date_entree'];
$point_entree = sanitize_text_field( $_POST['point_entree'] );
$contactUrgence = sanitize_text_field( $_POST['contactUrgence'] );
$emailUrgence = sanitize_email( $_POST['emailUrgence'] );
$telUrgence = sanitize_text_field( $_POST['telUrgence'] );
$catdeclarant = $_POST['catdeclarant'];
$fonction_agent = sanitize_text_field( $_POST['fonction_agent'] );
$commentaires = sanitize_text_field( $_POST['commentaires'] );
$nomPat = $_POST['nomPat'] ;
$postnomPat = $_POST['postnomPat'] ;
$prenomPat = $_POST['prenomPat'] ;
$datenaisPat = $_POST['datenaisPat'];
$sexePat = $_POST['sexePat'];
$etatcivil = $_POST['etatcivil'];
$nationalite_ID = $_POST['nationalite_ID'];
$telPat = $_POST['telPat'] ;
$emailPat = $_POST['emailPat'] ;
$domicilePat = $_POST['domicilePat'] ;
$commune_ID = $_POST['commune_ID'];
$ville = $_POST['ville'] ;
$paysvisites = $_POST['paysvisites'] ;
$date_entree = $_POST['date_entree'];
$point_entree = $_POST['point_entree'] ;
$contactUrgence = $_POST['contactUrgence'] ;
$emailUrgence = $_POST['emailUrgence'] ;
$telUrgence = $_POST['telUrgence'] ;
$catdeclarant = $_POST['catdeclarant'];
$fonction_agent = $_POST['fonction_agent'] ;
$commentaires = $_POST['commentaires'] ;
// insert data
$sql = "INSERT INTO cov_patient(NomPatient, PostnomPatient, PrenomPatient, DateNaisPatient, SexePatient, EtatCivil, Nationalite_ID, TelPatient, EmailPatient, DomicilePatient, Commune_ID, Ville, PaysVisites, DateEntree, PointEntree, ContactUrgence, EmailUrgence, TelUrgence, CatDeclarant, FonctionAgent) VALUES (:nomPat, :postnomPat, :prenomPat, :datenaisPat, :sexePat, :etatcivil, :nationalite_ID, :telPat, :emailPat, :domicilePat, :commune_ID, :ville, :paysvisites, :date_entree, :point_entree, :contactUrgence, :emailUrgence, :telUrgence, :catdeclarant, :fonction_agent, :commentaires)";
$req = $pdo->prepare($sql);
$req-> execute(array(
":nomPat" => $nomPat,
":postnomPat" => $postnomPat,
":prenomPat" => $prenomPat,
":datenaisPat" => $datenaisPat,
":sexePat" => $sexePat ,
":etatcivil" => $etatcivil ,
":nationalite_ID" => $nationalite_ID ,
":telPat" => $telPat ,
":emailPat" => $emailPat ,
":domicilePat" => $domicilePat ,
":commune_ID" => $commune_ID ,
":ville" => $ville ,
":paysvisites" => $paysvisites ,
":date_entree" => $date_entree ,
":point_entree" => $point_entree ,
":contactUrgence" => $contactUrgence ,
":emailUrgence" => $emailUrgence ,
":telUrgence" => $telUrgence ,
":catdeclarant" => $catdeclarant ,
":fonction_agent" => $fonction_agent ,
":commentaires" => $commentaires
)
);
echo 'Success.';
}
else
{
//call the form creation function
mon_formulaire_covid19(
$nomPat,
$postnomPat,
$prenomPat,
$datenaisPat,
$sexePat,
$etatcivil,
$nationalite_ID,
$telPat,
$emailPat,
$domicilePat,
$commune_ID,
$ville,
$paysvisites,
$date_entree,
$point_entree,
$contactUrgence,
$emailUrgence,
$telUrgence,
$catdeclarant,
$fonction_agent,
$commentaires
);
}
}