title: Duplicate MySQL Record with AI ID Field
body: <p>I am trying to duplicate my MySQL record using the following function. It says I have an error in my SQL, which I cannot see. I added a few echo's at the bottom to help diagnose. Also, is there any easier way that naming each row individually? (row[$x])?</p>
  
  <p>The function is basically reading whichever ID is posted to it, then writing it back into the DB as if the user was simply entering it themselves without pressing the duplicate button. </p>
  
  <p>I have tried other code on stack and I thought I'd write one I actually understood so here it is!</p>
  
  <p><strong>EDIT:</strong> It seems that my second query is the problematic one as well.</p>
  
  <p>Thank you!</p>
  
  <pre><code>function procDupRec(){
  
      $id = mysql_real_escape_string($_GET['duplicate']);
  
      $query = "SELECT * FROM contacts WHERE id=$id";
  
              $result = mysql_query($query);      
  
              while($row = mysql_fetch_row($result)){
  
              $category = $row[1];
              $dateEntered = $row[2];
              $account = $row[3];
              $firstName = $row[4];
              $lastName = $row[5];
              $company = $row[6];
              $titlePos = $row[7];
              $officeNum = $row[8];
              $phoneExt = $row[9];        
              $homeNum = $row[10];
              $mobileNum = $row[11];
              $pagerNum = $row[12];
              $faxNum = $row[13];
              $address1 = $row[14];
              $address2 = $row[15];
              $city = $row[16];
              $state = $row[17];
              $zip = $row[18];
              $email = $row[19];
              $website = $row[20];
              $notes = $row[21];  
              $editBit = $row[22];    
              $protection = $row[23];
              $lastIP = $_SERVER['REMOTE_ADDR'];
  
              }
  
              $query2 = mysql_query("INSERT INTO contacts (category, dateEntered, account, firstName, lastName, company, titlePos, officeNum, phoneExt, homeNum, mobileNum, pagerNum, faxNum, address1, address2, city, state, zip, email, website, notes, editBit, protection, lastIP) VALUES ('$category', '$dateEntered', '$account', '$firstName', '$lastName', '$company', '$titlePos', '$officeNum', '$phoneExt', '$homeNum', '$mobileNum', '$pagerNum', '$faxNum', '$address1', '$address2', '$city', '$state', '$zip', '$email', '$website', '$notes', '$editBit', '$protection', '$lastIP')");
  
              $result2 = mysql_query($query2);
  
              echo $query2;
  
              echo mysql_error();
  
  
  
  }
  </code></pre>