Hi guys,

I've created a simple plugin for Wordpress that interacts with an API in the backend.
The problem is that everything is inserted twice in the database, and I cannot figure out why.

The form is submiting only once, not twice.

What could it be ?
Redirects from my .htaccess ?

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]

# END WordPress

My function from the plugin, this is the logs table and after that i'm calling get_curl_data() function.

function verifica_disponibilitate_curl($post) {
    $sdstr = '';

    global $wpdb;

    $insert = "INSERT IGNORE INTO ".$tblname." (data_verificata) VALUES('".$wbdb->escape($post['data_verificata'])."');";

    $rows_affected = $wpdb->query($insert);
    $curl = get_curl_data($post['data_verificata']);

    if(count($curl) == 0) {
        $sdstr = 'Datele de configurare API nu sunt corecte!';
    } else {
        $sdstr = $curl['mesaj'];

    return $sdstr;
}#function verifica_disponibilitatea

The get_curl_data() function looks like this.

function get_curl_data($data_verificata = '') {

    global $wpdb;

    $select = "SELECT * FROM ".$tblname."";
    $query = $wpdb->get_results($select);  

    foreach($query as $data) {
    // Datele de conectare pentru API 
        $username  = $data->username; 
        $password  = $data->password;
    // Data Cautata         
    $data = $data_verificata; 

    // Apelarea host-ului pentru rezultate impreuna cu data cautata 
    $host = "http://bysobi.com/api/disponibilitate/data/api/".$data; 

    // Initializare curl pentru a extrage rezultatele 
    $process = curl_init($host); 
        curl_setopt($process, CURLOPT_HEADER, FALSE); 
        curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password); 
        curl_setopt($process, CURLOPT_TIMEOUT, 30); 
        curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE); 
    $response = curl_exec($process);
    return json_decode($response,true);

It looks like that there is something with my particular blog, it redirects for some resource, I've installed the plugin to other pages and it works without problems! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.