MySQL / PHP Insert the same row twice

Please, help. I believe I have a reasonable understanding of MySql and PHP, but for the life of me I can't figure out why this code is inserting the same line twice. I've literally stripped it down to the following code:

<?php

$query = "INSERT INTO `cs_social_alerts` (email) VALUES ('test@test.com')";
mysql_query($query);

?>

      

The MySQL table it inserted has 10 columns, but even with all of them mentioned in the query, it still inserts " test@test.com " on two rows with separate primary keys.

I created a new Wordpress page to run it as all other pages work fine without duplication.

I did some Googling which didn't find any help whatsoever. Is there anyway I can check where the second request is coming from? I've starred in this code for about an hour and don't see any problems with it.

Any ideas / help appreciated A LOT!

thank

----- EDIT -----

So here is the debug debug output, the code that runs is literally 2 lines above - I closed the domain for security. Can anyone see any interference? I'm not a PHP expert and with all the unnecessary Wordpress stuff, I'm not sure what! Thanks guys

0 eval () called at [/var/sites/c/****.com/public_html/wp-content/plugins/wp-exec-php/wp-exec-php.php:652]

1 WP_exec_PHP-> exec (

$ myQuery = "INSERT INTO cs_social_alerts

(email) VALUES (' test@test.com ')";

mysql_query ($ myQuery);

debug_print_backtrace ()

? >

) called in [/ var / sites / c / ****. com / public_html / wp-content / plugins / wp-exec-php / wp-exec-php.php: 692]

2 WP_exec_PHP → _ exec_post (

$ myQuery = "INSERT INTO cs_social_alerts

(email) VALUES (' test@test.com ')";

mysql_query ($ myQuery);

debug_print_backtrace ()

? >

)

3 call_user_func_array (Array ([0] => WP_exec_PHP object ([] => Array (), [] => / var / sites / c / * .com / public_html / wp- content / plugins / wp-exec-php / wp-exec-php.php), [1] => _exec_post), Array ([0] =>

$ myQuery = "INSERT INTO cs_social_alerts

(email) VALUES (' test@test.com ')";

mysql_query ($ myQuery);

debug_print_backtrace ()

? >

)) called in [/ var / sites / c / * .com / public_html / wp-includes / plugin.php: 192]

4 apply_filters (the_content,

$ myQuery = "INSERT INTO cs_social_alerts

(email) VALUES (' test@test.com ')";

mysql_query ($ myQuery);

debug_print_backtrace ()

? >

+3


source to share


4 answers


I had the same problem and it was a chrome bug! I clear sessions, cookies, cache, all data apps and it works.



+1


source


Use PHP's debug_print_backtrace () function to see where your code is being called from.



0


source


Try PHP Data Object ( PDO ). The use of mysql_ * functions is deprecated.

These variable initializations must be defined in the ini file that you use php_parse_ini () to retrieve the data.

<?php        
    $host = "host=localhost";
    $name = ";dbname=name_of_db";
    $user = "user";
    $pass = "pass";

    $conn = new PDO("mysqli:".$host.$name,$user,$pass);
    $stmt = $conn->prepare("INSERT INTO `cs_social_alerts` (email) VALUES (:email)");
    $stmt->bindParam(':email', $email);
    $stmt->execute();

      

Also, if you want to know if this code runs more than once. Try setting the $ _SESSION variable. I.E. $ _SESSION ['count'] = 0; Then just before execute () put $ _SESSION ['count'] ++; Finally, print the $ _SESSION value at the end of the code to determine what that value is.

var_dump($_SESSION);die();

      

0


source


Have you tried another browser? I was in a lot of trouble because some of the extensions I had in my browser were requesting the page again.

Even if this is not your problem, I think you should check external factors as this code cannot insert two lines. Unless, of course, it gets called twice.

0


source







All Articles