The problem is i write a code that works pretty fine in local but when i insert it in wordpress using “insert php” plugin , i have 3 entries instead of one.
Here is my code :

[insert_php]

$hostname = 'hostname';
$user = 'user';
$password = 'password';
$dbname = 'dbname';
$connect = mysqli_connect($hostname, $user, $password, $dbname);
if (mysqli_connect_error()){
    die('Erreur('.mysqli_connect_errno()
        .mysqli_connect_error());
}
$select = "SELECT id FROM tderouleurs WHERE id = (SELECT MAX(id) FROM tderouleurs)";
$res = mysqli_query($connect, $select);


[/insert_php]

<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <br>
    <br>
</div>
<form method="post" action="The link of the webpage here">
    <label for="region">Nom de la région</label>
    <input type="text" name="region" id="region" value="">
    <label for="structure">Structure</label>
    <select name="structure" id="structure">
        <option value="entreprise">entreprise</option>
        <option value="association">association</option>
        <option value="structures">structures publiques</option>
    </select>
    <label for="secteur">Secteur</label>
    <select name="secteur" id="secteur">
        <option value="public">Public</option>
        <option value="prive">Privé</option>
    </select>
    <label for="theme">Théme</label>
    <select id="theme" name="theme">
        <option value="Environnement">Environnement</option>
        <option value="Innovation">Innovation</option>
        <option value="Tourisme">Tourisme</option>
        <option value="Sports">Sports</option>
     </select>
    <label for="nom_financeur">Nom financeur</label>
    <input type="text" name="nom_financeur" id="nom_financeur" value="">
    <label for="lien_financeur">Lien financeur</label>
    <input type="text" name="lien_financeur" id="lien_financeur" value="">
    <input type="submit" value="Envoyer" name="envoyer">
</form>
[insert_php]
$_region = filter_input(INPUT_POST, 'region', FILTER_SANITIZE_STRING);
$_structure = filter_input(INPUT_POST,'structure',FILTER_SANITIZE_STRING);
$_secteur = filter_input(INPUT_POST, 'secteur', FILTER_SANITIZE_STRING);
$_financeur = filter_input(INPUT_POST, 'nom_financeur', FILTER_SANITIZE_STRING);
$_theme = filter_input(INPUT_POST, 'theme', FILTER_SANITIZE_STRING);
$_lien_financeur = filter_input(INPUT_POST, 'lien_financeur', FILTER_SANITIZE_STRING);
$_envoyer = filter_input(INPUT_POST, 'envoyer', FILTER_SANITIZE_STRING);
$insert = "INSERT INTO tderouleurs (id,region,structure,secteur,theme,financeur,lien_financeur) VALUES(DEFAULT, '$_region', '$_structure', '$_secteur', '$_theme','$_financeur', '$_lien_financeur') ";
if(isset($_envoyer)) {
    $resInsert = mysqli_query($connect, $insert);
}
[/insert_php]
</body>
</html>

Is it possible that wordpress loads the script thrice ? I tried with the function “exit()” at the end of my script , i had just one entrie instead of three this time but i have either a blank page or a page with wierd elements like one of the selects and one of the inputs was fusionned , a lot of things in wordpress doesn’t make sense i know … i tried to do a query with REPLACE instead of INSERT but still no luck …

Read more here: WordPress php mysqli insert 3 entries instead of one


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.


Wordpress related questions and answers: