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
Unable to update a field in a custom table
#1
In the edit_profile.php, i modified it to update a payment field in a Members table but it is not updating.

         //Update Payment Type
        if ($userdetails->payment_type != $_POST['payment_type']){
            $payment_type = ucfirst(Input::get("payment_type"));
            $fields=array('payment_type'=>$payment_type);
            $validation->check($_POST,array(
                'payment_type' => array(
                    'display' => 'Payment Type',
                    'required' => true,
                    'min' => 1,
                    'max' => 255
                )
            ));
            if($validation->passed()){
                $db->update('users',$userId,$fields); I changed it to this ->([b]$db->update('member',$userId,$fields)[/b]
                $successes[]='Payment Type updated.';
                                logger($user->data()->id,"User","Changed payment_type from $userdetails->payment_type to $payment_type.");
            }else{
                //validation did not pass
                foreach ($validation->errors() as $error) {
                    $errors[] = $error;
                }
            }
        }else{
            $payment_type=$userdetails->payment_type;
        }


What am i doing wrong?
  Reply
#2
I haven't seen your members table, but I'm guessing when you look at the column names,  the id and user id are two different columns.  Right?  The update query expects that you're updating by id.

So in other words if I have a row id of 12 but my user_id column is 20, the update query would be looking to update the row 12.  So you need to specify the column name that you're attaching it to. I'll assume it's userid just for demo purposes.

it would be
$db->update('member',['userid','=',$userId],$fields);

So in yours $db->update('member',$userId,$fields), that middle $userid gets changed into an array of [columname,operator,data]

One other note, if you have a query that you're having issues with, you can do...
dnd($db->errorInfo());  or dump($db->errorInfo()); and you'll usually get error messages that tell you what's wrong.
  Reply
#3
(10-03-2018, 09:52 AM)mudmin Wrote: I haven't seen your members table, but I'm guessing when you look at the column names,  the id and user id are two different columns.  Right?  The update query expects that you're updating by id.

So in other words if I have a row id of 12 but my user_id column is 20, the update query would be looking to update the row 12.  So you need to specify the column name that you're attaching it to. I'll assume it's userid just for demo purposes.

it would be
$db->update('member',['userid','=',$userId],$fields);

So in yours $db->update('member',$userId,$fields), that middle $userid gets changed into an array of [columname,operator,data]

One other note, if you have a query that you're having issues with, you can do...
dnd($db->errorInfo());  or dump($db->errorInfo()); and you'll usually get error messages that tell you what's wrong.
Ok thanks. will work on that.
  Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)