简体   繁体   English

MySQL / PHP两次插入同一行

[英]MySQL/PHP Inserting the same row twice

Please help. 请帮忙。 I consider myself to have a reasonable understanding of MySql & PHP, but for the life of me I can't figure out why this code is inserting the same row twice. 我认为自己对MySql和PHP有一个合理的理解,但对于我的生活,我无法弄清楚为什么这段代码两次插入同一行。 I've literally stripped it back to the following code: 我真的把它剥离回以下代码:

<?php

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

?>

The MySQL table it's being inserted into has 10 columns in it, but even with all of them mentioned in the query, it still inserts 'test@test.com' on two rows, with separate primary keys. 它所插入的MySQL表中有10列,但即使查询中提到了所有这些列,它仍会在两行上插入“test@test.com”,并带有单独的主键。

I've created a new Wordpress page to run this on as all other pages seem to be functioning fine without the duplication. 我创建了一个新的Wordpress页面来运行它,因为所有其他页面似乎运行正常,没有重复。

I've done some Googling which hasn't found much of any help - Is there anyway I can check where the second query is coming from? 我做了一些谷歌搜索没有找到任何帮助 - 无论如何我可以检查第二个查询来自哪里? I've starred at the above code for about an hour now and cannot see any issues with it. 我已经对上面的代码进行了大约一个小时的演出,并且看不出任何问题。

Any ideas/help MUCH appreciated! 任何想法/帮助很多人赞赏!

Thanks 谢谢

----- EDIT ----- -----编辑-----

So here's the result from the debug traceback, the code that's being run is literally the 2 lines above - I've blanked the domain for security. 所以这是调试回溯的结果,正在运行的代码实际上是上面的两行 - 我已经将域空白以保证安全性。 Can anyone see any interference? 谁能看到任何干扰? I'm no PHP expert and with all the extra Wordpress stuff thrown in, I'm not sure what's what! 我不是PHP专家,并且所有额外的Wordpress内容都被抛入,我不确定是什么! Thanks guys 多谢你们

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

1 WP_exec_PHP->exec( 1 WP_exec_PHP-> exec(

$myQuery = "INSERT INTO cs_social_alerts (email) VALUES ('test@test.com')"; $ myQuery =“INSERT INTO cs_social_alerts (email)VALUES('test@test.com')”;

mysql_query($myQuery); 的mysql_query($更改为MyQuery);

debug_print_backtrace() debug_print_backtrace()

?> ?>

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

2 WP_exec_PHP->_exec_post( 2 WP_exec_PHP - > _ exec_post(

$myQuery = "INSERT INTO cs_social_alerts (email) VALUES ('test@test.com')"; $ myQuery =“INSERT INTO cs_social_alerts (email)VALUES('test@test.com')”;

mysql_query($myQuery); 的mysql_query($更改为MyQuery);

debug_print_backtrace() 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] => 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),数组([0] =>

$myQuery = "INSERT INTO cs_social_alerts (email) VALUES ('test@test.com')"; $ myQuery =“INSERT INTO cs_social_alerts (email)VALUES('test@test.com')”;

mysql_query($myQuery); 的mysql_query($更改为MyQuery);

debug_print_backtrace() debug_print_backtrace()

?> ?>

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

4 apply_filters(the_content, 4 apply_filters(the_content,

$myQuery = "INSERT INTO cs_social_alerts (email) VALUES ('test@test.com')"; $ myQuery =“INSERT INTO cs_social_alerts (email)VALUES('test@test.com')”;

mysql_query($myQuery); 的mysql_query($更改为MyQuery);

debug_print_backtrace() debug_print_backtrace()

?> ?>

I had the same problem, and it was chrome fault! 我有同样的问题,这是铬故障! I clear the sessions, cookies, cache, all data application and it works. 我清除会话,cookie,缓存,所有数据应用程序,它的工作原理。

使用PHP函数debug_print_backtrace()来查找调用代码的位置。

Try a PHP Data Object( PDO ). 尝试PHP数据对象( PDO )。 Using the mysql_* functions are obsolete. 使用mysql_ *函数已经过时了。

These variable initializations should be defined in an ini file that you use php_parse_ini () to get the data from. 这些变量初始化应该在您使用php_parse_ini ()从中获取数据的ini文件中定义。

<?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 is getting run more than once. 此外,如果您想知道此代码是否多次运行。 Try setting a $_SESSION variable. 尝试设置$ _SESSION变量。 IE $_SESSION['count'] = 0; IE $ _SESSION ['count'] = 0; Then right before execute() put $_SESSION['count']++; 然后就在execute()之前放入$ _SESSION ['count'] ++; Finally, dump the value of $_SESSION at the end of your code to determine what the value is. 最后,在代码末尾转储$ _SESSION的值以确定值是什么。

var_dump($_SESSION);die();

Have you tried another browser? 你试过另一个浏览器吗? I had plenty of bad experiences because some extensions that I had in my browser were requesting the page one more time. 我有很多糟糕的经历,因为我在浏览器中的一些扩展程序再次请求页面。

Even if that's not your problem, I think you should check for external factors, as this code cannot insert two rows. 即使这不是你的问题,我认为你应该检查外部因素,因为这段代码不能插入两行。 Unless, of course, it's being called twice. 当然,除非它被召唤两次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM