mysql inserting records twice in database

喜欢而已 提交于 2020-01-14 04:52:28

问题


I have the simple code shown below. After it has run once, it inserts the results into MySQL database twice. It is working fine in all browsers (IE, Chrome, and Safari) except Firefox.

I am using symfony php framework and propel as the ORM.

$con = Propel::getConnection();
   $sql =  "select * from tmp where user_id =$userid";  
   $stmt = $con->prepare($sql);  
   $stmt->execute(); 
   while($row = $stmt->fetch(PDO::FETCH_ASSOC))
   {
    $insert_sql = "INSERT IGNORE into library(xxx,xxx) VALUES('xyz','xys')";
    $insert_stmt = $con->prepare($insert_sql) ;
    $insert_stmt->execute();
   }

回答1:


Most of time it's being a consequence of unwise mod_rewrite usage, making some file act as a 404 error handler.
Thus, if some resource not found, such a file being called and executed.

Check HTTP headers when calling your page and see what additional requests being made.




回答2:


The problem is deeper.I am not a php developer, but I can understand the problem is the design. Ideally I think your client is making multiple request to your server and each request is inserting a record in the system before checking if the record already exists.



来源:https://stackoverflow.com/questions/5609713/mysql-inserting-records-twice-in-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!