The following warnings occurred:
Warning [2] Undefined variable $unreadreports - Line: 26 - File: global.php(961) : eval()'d code PHP 8.1.2-1ubuntu2.14 (Linux)
File Line Function
/global.php(961) : eval()'d code 26 errorHandler->error
/global.php 961 eval
/printthread.php 16 require_once



UserSpice
Option to Insert record in admin_user.php - Printable Version

+- UserSpice (https://userspice.com/forums)
+-- Forum: Support Center (https://userspice.com/forums/forumdisplay.php?fid=23)
+--- Forum: UserSpice 4.3 and Below (https://userspice.com/forums/forumdisplay.php?fid=26)
+--- Thread: Option to Insert record in admin_user.php (/showthread.php?tid=1170)



Option to Insert record in admin_user.php - eforbes - 10-11-2018

I want to insert a record in a table on the admin_user.php page.
The option is located in the Misc Settings modal dialog box right beside the Delete user option.
(Between Lines 610 - 650)


The code is as follows:


 <label>Clone this User?
      <input type='checkbox' name='clone[<?php echo "$userId"; ?>]' id='clone[<? echo "$userId"; ?>]' value='<?php echo "$userId"; ?>' <?php if (!checkMenu(2,$user->data()->id) || $userId == 1){  ?>disabled<?php } ?>></label>
      </div>



(Between lines 50 - 60) under the "Form posted" section, right beneath the deletion Post, the code is as follows:

 if(!empty($_POST['clone'])){

    $db->insert("members", ["memberid"=>$userId]);

    }

When I click the update button, nothing is going to the database. I use the dnd($variable); and i see the value of the userId but I have no idea why that record is not inserted.

Need some help urgently!!!!!!!!!!!


RE: Option to Insert record in admin_user.php - usamusa - 10-11-2018

I think your input should be something like:
Code:
<input type='checkbox' name='clone[userId]' id='clone[<? echo "$userId"; ?>]'
value='<?php echo "$userId"; ?>' <?php if (!checkMenu(2,$user->data()->id) || $userId == 1){  ?>disabled<?php } ?>>

and the form processing code:
Code:
if(!empty($_POST['clone'])){
   $userID = $_POST['clone']['userId'];
    $db->insert("members", ["memberid"=>$userID]);
}



RE: Option to Insert record in admin_user.php - eforbes - 10-11-2018

Tried it and the it broke the page.  It throws a HTTP ERROR 500


RE: Option to Insert record in admin_user.php - usamusa - 10-11-2018

Yes, I edited my reply, it had an extra braket :p
I Just tried it, it works now
hope it helps


RE: Option to Insert record in admin_user.php - eforbes - 10-11-2018

Sill a page break.

Where exactly did you put the if statement?

mine is just below the delete $POST like this:

else
{

 if(!empty($_POST['clone'])){
      $userID = $_POST['clone']['userId']; 
      $db->insert("members", ["memberid"=>$userID]);
      }

}

and my input is just below the delete label like this:

 <label><input type='checkbox' name='clone[userId]' id='clone[<? echo "$userId"; ?>]' value='<?php echo "$userId"; ?>' <?php if (!checkMenu(2,$user->data()->id) || $userId == 1){  ?>disabled<?php } ?>></label>


RE: Option to Insert record in admin_user.php - usamusa - 10-12-2018

I think a working example for you would be the following:

Form input (yes after the delete label):
Code:
<label>Clone this user?
      <input type='checkbox' name='clone[userId]' id='clone[<?php echo "$userId"; ?>]'
value='<?php echo $userId; ?>' <?php if (!checkMenu(2,$user->data()->id) || $userId == 1){  ?>disabled<?php } ?>>
</label>

and the form processing php:
Code:
  if(!empty($_POST['delete'])){
    $deletions = $_POST['delete'];
    if ($deletion_count = deleteUsers($deletions)){
      logger($user->data()->id,"User Manager","Deleted user named $userdetails->fname.");
                Redirect::to($us_url_root.'users/admin_users.php?msg='.lang("ACCOUNT_DELETIONS_SUCCESSFUL", array($deletion_count)));
    }
    else {
      $errors[] = lang("SQL_ERROR");
    }
  }

// here is the clone input
 elseif(!empty($_POST['clone'])){
      $userID = $_POST['clone']['userId'];
      $db->insert("members", ["memberid"=>$userID]);
      //dnd($_POST['clone']);
}
// end of clone input

  else
  {

    if(!empty($_POST['cloak'])){......

I hope you find this helpful


RE: Option to Insert record in admin_user.php - eforbes - 10-12-2018

Got it!  Thanks usamusa.  I had two extra curly braces in the clone $POST statement


RE: Option to Insert record in admin_user.php - Brandin - 10-13-2018

eforbes:

I am glad this is now working, but I recommend you also turn on Error Reporting so you can find the actual errors instead of just knowing it returned 500.

Brandin.


RE: Option to Insert record in admin_user.php - eforbes - 10-16-2018

(10-13-2018, 03:53 PM)Brandin Wrote: eforbes:

I am glad this is now working, but I recommend you also turn on Error Reporting so you can find the actual errors instead of just knowing it returned 500.

Brandin.

I am almost certain I did but I will definitely make sure next time around.