开发者

PHP: Getting duplicate inserts when utilizing SQLite

At the beginning of my script I delete everything in the table. When running the code below it is iterating 3 times (o开发者_开发问答ne for each record) however when I check the data after the fact the information is being duplicated (6 inserts instead of 3).

  foreach ($response2->records as $record) {    

    $accountid = $record->fields->AccountId;
    $resident_title = $record->fields->Resident_Title__c;
    $supervisor_title = $record->fields->Supervisor_Title__c;
    $position_proposal_url = $record->fields->Position_Proposal_URL__c;  

    $sql = "INSERT INTO Positions (AccountID, Position_Title, Supervisor_Title, Position_Url) 
    VALUES ('$accountid',
    '$resident_title',
    '$supervisor_title',
    '$position_proposal_url');";

    $result2 = $database->exec($sql);
  } 

I have inserted a print command prior to the last line to determine the content of the SQL and to visualize that it is in fact only looping through 3 times. So based on that I suspect the problem must be with my PHP/SQL syntax.


Do you have a CSS or inline style that has an empty background url?

Fire up your page using Firefox/Firebug or something similar that will allow you to trap all http traffic - it is most likely your page is being hit twice.


I'm pretty sure your database shouldn't be allowing duplicate rows. Fix that problem, and attempts to insert duplicate keys should cause an error you can follow.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜