Jump to content

[SOLVED] Copy auto-increment value to another row on insert


pfkdesign

Recommended Posts

hi guys,

 

i have a problem and i don't know how to solve it  ???  :'(, i would like to copy the value of id (which is auto-increment) to another field on the same table "when i inserting a record".

ex:

| table                |

--------------------    i would like to copy "id" to "c_id" when i insert record

|  id      int A.PK |

|  c_id    int        |

|  label              |

--------------------

 

thank you in advance. :P

 

$sql = "INSERT INTO `tablename` (`label`) VALUES ('labelname')";
$res = mysql_query($sql) or die(mysql_error());
$id = mysql_insert_id();
$update = "UPDATE `tablename` SET `c_id` = '$id' WHERE `id` = '$id'";
$ures = mysql_query($update) or die(mysql_error());

 

Ray

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.