Duplicate one row in a MYSQL table through PHP

/ Published in: PHP
Save to your folder(s)

Copy this code and paste it in your HTML
  1. function duplicateRow($table,$primaryField,$primaryIDvalue) {
  2. // duplicate one record in a table
  3. // and return the id
  4. $fields = getCommaFields($table,$primaryField);
  5. $sql = "insert into $table ($fields) select $fields from $table where $primaryField='".mysql_real_escape($primaryIDvalue)."' limit 0,1";
  6. mysql_query($sql) or die(mysql_error().$sql);
  7. return mysql_insert_id();
  8. }

URL: http://www.barattalo.it/2010/01/25/10-php-usefull-functions-for-mysql-stuff/

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.