addForm.php to editForm.php

5 posts by 3 authors in: Forums > CMS Builder
Last Post: July 10, 2014   (RSS)

By gkornbluth - July 7, 2014

Hi Perch,

Have a look at the code in the member profile update form in the Membership plugin, it should give you the basic code for matching and updating an existing record.

There's also a recipe or two in the CMSB Cookbook http://www.thecmsbcookbook.com about updating record fields.

Look at the one called POPULATING A FORM FROM A MULTI RECORD DATABASE, UPDATING RECORDS, CREATING NEW RECORDS and UPDATING A RECORD ONLY WHERE AN INPUT FIELD MATCHES A RECORD FIELD VALUE

They should be of some help,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Perchpole - July 8, 2014

Hi, Jerry -

Good idea re the membership plugin. I'll take a look.

Also thanks for reminding me about the Cookbook. Lots of good stuff in there!

:0)

Perch

By Dave - July 8, 2014

Hi Perch, 

Here's some code snippets using some of our latest library functions:

// add record
$colsToValues = array(); // these fields get automatically mysql escaped unless you end fieldname with =
$colsToValues['createdDate=']     = 'NOW()';
$colsToValues['updatedDate=']     = 'NOW()';
$colsToValues['createdByUserNum'] = @$CURRENT_USER['num'];
$colsToValues['updatedByUserNum'] = @$CURRENT_USER['num'];
$colsToValues['title']            = @$_REQUEST['title'];
$hideMissingFieldErrors = true;
$newRecordNum = mysql_insert($tablename, $colsToValues, $hideMissingFieldErrors);

// update record
$recordNum    = 123;  // you can use either or both of $recordNum And $where
$where        = null; // lookup by recordNum only
$colsToValues = array(); // these fields get automatically mysql escaped unless you end fieldname with =
$colsToValues['updatedDate=']     = 'NOW()';
$colsToValues['updatedByUserNum'] = @$CURRENT_USER['num'];
$colsToValues['title']            = @$_REQUEST['title'];
mysql_update($tablename, $recordNum, $where, $colsToValues);

Hope that helps, cheers!

Dave Edis - Senior Developer
interactivetools.com

By Perchpole - July 10, 2014

Hi, Dave

Thanks for this. It would be great if someone would update the Uploadform.php with the new code options. 

Perchpole