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
/showthread.php 28 require_once





× This forum is read only. As of July 23, 2019, the UserSpice forums have been closed. To receive support, please join our Discord by clicking here. Thank you!

  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Option to Insert record in admin_user.php
#1
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!!!!!!!!!!!
  Reply
#2
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]);
}
  Reply
#3
Tried it and the it broke the page.  It throws a HTTP ERROR 500
  Reply
#4
Yes, I edited my reply, it had an extra braket :p
I Just tried it, it works now
hope it helps
  Reply
#5
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>
  Reply
#6
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
  Reply
#7
Got it!  Thanks usamusa.  I had two extra curly braces in the clone $POST statement
  Reply
#8
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.
  Reply
#9
(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.
  Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)