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
Unable to update a field in a custom table - 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: Unable to update a field in a custom table (/showthread.php?tid=1158)



Unable to update a field in a custom table - eforbes - 10-02-2018

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?


RE: Unable to update a field in a custom table - mudmin - 10-03-2018

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.


RE: Unable to update a field in a custom table - eforbes - 10-03-2018

(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.