首页 文章

MySQL / PHP两次插入同一行

提问于
浏览
3

请帮忙 . 我认为自己对MySql和PHP有一个合理的理解,但对于我的生活,我无法弄清楚为什么这段代码两次插入同一行 . 我真的把它剥离回以下代码:

<?php

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

?>

它所插入的MySQL表中有10列,但即使查询中提到了所有这些列,它仍会在两行上插入“test@test.com”,并带有单独的主键 .

我创建了一个新的Wordpress页面来运行它,因为所有其他页面似乎运行正常,没有重复 .

我做了一些谷歌搜索没有找到任何帮助 - 无论如何我可以检查第二个查询来自哪里?我已经对上面的代码进行了大约一个小时的演出,并且看不出任何问题 .

任何想法/帮助很多人赞赏!

谢谢

-----编辑-----

所以这是调试回溯的结果,正在运行的代码实际上是上面的两行 - 我已经将域空白以保证安全性 . 谁能看到任何干扰?我不是PHP专家,并且所有额外的Wordpress内容都被抛入,我不确定是什么!多谢你们

0 eval()在[/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()

?>

)来自[/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),[]] => _exec_post),数组([0] =>

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

的mysql_query($更改为MyQuery);

debug_print_backtrace()

?>

))调用[/ 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()

?>

4 回答

  • 0

    我有同样的问题,这是铬故障!我清除会话,cookie,缓存,所有数据应用程序,它的工作原理 .

  • 0

    使用PHP函数debug_print_backtrace()找出调用代码的位置 .

  • 1

    尝试PHP数据对象(PDO) . 使用mysql_ *函数已经过时了 .

    这些变量初始化应该在您使用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();
    

    此外,如果您想知道此代码是否多次运行 . 尝试设置$ _SESSION变量 . I.E. $ _SESSION ['count'] = 0;然后就在execute()之前放入$ _SESSION ['count'];最后,在代码末尾转储$ _SESSION的值以确定值是什么 .

    var_dump($_SESSION);die();
    
  • 0

    你试过另一个浏览器吗?我有很多糟糕的经历,因为我在浏览器中的一些扩展程序再次请求页面 .

    即使这不是你的问题,我认为你应该检查外部因素,因为这段代码 cannot 插入两行 . 当然,除非它被召唤两次 .

相关问题