Add generated record number to an additional field upon INSERT INTO

5 posts by 2 authors in: Forums > CMS Builder
Last Post: January 22, 2015   (RSS)

By nmsinc - January 22, 2015

 The INSERT code below creates a new record - I want to capture the new record number and also save it in the "file_number" field upon saving the record.

Not sure on how this is done - any help would be appreciated - Thanks

nmsinc

mysql_query("INSERT INTO `{$TABLE_PREFIX}background` SET

title         = '".mysql_escape( $_REQUEST['title'] )."',
alert         = '".mysql_escape( $_REQUEST['alert'] )."',   
file_number   = ???????
discontinue   = '".mysql_escape( $_REQUEST['discontinue'] )."'")

or die("MySQL Error Creating New Claim Type Record:<br/>\n". htmlspecialchars(mysql_error()) . "\n");
$userNum = mysql_insert_id();

nmsinc

By claire - January 22, 2015

Not sure what you mean here - you need the record num to be saved into its own record?

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

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By claire - January 22, 2015

Okay, you'll need to add this line after your code:

$userNum = mysql_insert_id();
mysql_update('background', $userNum, null, array('file_number' => $userNum));

And then remove the line referencing file_number from the actual query.

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

Claire Ryan
interactivetools.com

Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By nmsinc - January 22, 2015

Thanks Claire - worked great!

nmsinc

nmsinc