Updating user record outside of CMS ?
3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 3, 2012 (RSS)
By nmsinc - April 3, 2012
I have created a form to update users outside the CMS. I can pull the user in, however, when I submit the changes the page errors out at the 404 error catch which tells me that it is not parsing the user number in the URL!
Here is page top with 404 error catch:
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('','../','../../','../../../','../../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load records
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'where' => whereRecordNumberInUrl(1),
));
$accountsRecord = @$accountsRecords[0]; // get first record
// show error message if no matching record is found
if (!$accountsRecord) { dieWith404("Record not found!"); }
Here is the form submit code:
<form method="post" action="http://www.claimscaddy.com/user-profile-admin-update.php?<?php echo htmlspecialchars(@$_REQUEST['num']); ?>">
<input type="hidden" name="save" value="1" />
Any ideas anyone? – Thanks nmsinc[/#000000]
Here is page top with 404 error catch:
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('','../','../../','../../../','../../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load records
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'where' => whereRecordNumberInUrl(1),
));
$accountsRecord = @$accountsRecords[0]; // get first record
// show error message if no matching record is found
if (!$accountsRecord) { dieWith404("Record not found!"); }
Here is the form submit code:
<form method="post" action="http://www.claimscaddy.com/user-profile-admin-update.php?<?php echo htmlspecialchars(@$_REQUEST['num']); ?>">
<input type="hidden" name="save" value="1" />
Any ideas anyone? – Thanks nmsinc[/#000000]
nmsinc
Re: [nmsinc] Updating user record outside of CMS ?
By (Deleted User) - April 3, 2012
Hello nmsinc,
The best solution would be to send the user number as a hidden field (like the 'save' field) rather than directly through the url.
This will leave your code much cleaner and much easier to read/update:
Then when you are retrieving the record for the update, you can check if the 'num' has been passed in POST. If it has, use that num to search for the user info. If not, default to the 'whereRecordNumberInUrl' function:
You don't have to refer to the user number as 'num', you can call it whatever you want - I just used num because that's the easiest thing to remember!
Hope this helps,
Tom
The best solution would be to send the user number as a hidden field (like the 'save' field) rather than directly through the url.
This will leave your code much cleaner and much easier to read/update:
<form method="post" action="user-profile-admin-update.php">
<input type="hidden" name="save" value="1" />
<input type="hidden" name="num" value="<?php echo $accountsRecord['num']; ?>" />
Then when you are retrieving the record for the update, you can check if the 'num' has been passed in POST. If it has, use that num to search for the user info. If not, default to the 'whereRecordNumberInUrl' function:
$where = whereRecordNumberInUrl(1);
if ( @$_REQUEST['num'] ) { $where = "num='".$_REQUEST['num']."'"; }
list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'where' => $where,
));
$accountsRecord = @$accountsRecords[0]; // get first record
You don't have to refer to the user number as 'num', you can call it whatever you want - I just used num because that's the easiest thing to remember!
Hope this helps,
Tom
Re: [Tom P] Updating user record outside of CMS ?
By nmsinc - April 3, 2012
Hi Tom,
Worked - Thanks!
Worked - Thanks!
nmsinc