SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,051
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    inserting into mysql db using PEAR within a loop

    Hi Guys,

    I am trying to insert data into a MYSQL database using PEAR, see below for code. The problem I am having is that it only adds one entry and not the 5 that are expected. Any ideas what may be causing this?

    PHP Code:
    foreach($Array as $Value) {
       
    $this->dbh->query("insert into table (field_1,field_2) values ('Value1','Value2')");
       
    // Get new user id;
       
    $NewUserId mysql_insert_id($this->dbh->connection);


  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Probably because:

    1. $Array has only one element
    2. At least one of the fields has a unique constraint, which would fail any but the first insert -- you're inserting same values on every iteration
    Saul


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •