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



UserSpice
Help with $dv->update - 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: Help with $dv->update (/showthread.php?tid=509)



Help with $dv->update - muhammedc - 03-29-2017

Hi

So heres the code I am using... but it doesnt seem to update the db... I cant seem to figure out where I am going wrong:

require_once $abs_us_root.$us_url_root.'users/classes/DB.php';'

$db = DB::getInstance();
$updatestatus = Input::Get('update');
$qid = Input::Get('id');

if ($updatestatus != 1) {
$fields = array(
'author' => $user->data()->id,
'filenumber' => Input::get('internal'),
'content' => Input::get('letterbody'),
'webkey' => Token::generate(),
);
$db->insert('letters',$fields);
Redirect::to('lettersearch.php?msg=Letter+Saved!');
}
else {
$fields = array(
'lastupdatedby' => $user->data()->id,
'filenumber' => Input::get('internal'),
'content' => Input::get('letterbody'),
);

$db->update('letters',$qid,$fields);
dump ($fields);
Redirect::to('lettersearch.php?msg=Letter+Updated!');
}


Any ideas what I am not seeing? There are no errors. If I goto the database, any changes made in any of the fields above do not get updated...


Help with $dv->update - mudmin - 03-30-2017

So here are the steps I would take.

I would start simple.

1. I would include the
Code:
users/init.php
instead of just the db class. There are other things you may need beyond just the db class. The most obvious thing is that you're using Input::get which is part of the input class which you haven't included.

Start there and see if that works.

2. If it doesn't, I would do something really simple just to make sure you're able to get SOMETHING into the DB. Without including the init, it probably doesn't even know the $user->data()-id, which is probably part of your problem, so once you've included the init, try doing

Code:
if ($updatestatus != 1) {
Code:
$db->insert('letters',['author'=>$user->data()->id]);
Code:
}

And make sure you're getting that into the db. If you need help beyond that, let me know.




Help with $dv->update - muhammedc - 03-30-2017

Got it to work... silly me noticed now that this:

Code:
$fields = array(
Code:
‘lastupdatedby’ => $user->data()->id,


was actually suppose to be:

Code:
$fields = array(
Code:
‘lasteditedby’ => $user->data()->id,


So in essence I has the wrong name for the DB field...

Thanks for your help buddy... Much appreciated Smile


Help with $dv->update - mudmin - 03-30-2017

Yep. No problem. I wish there was a better way to get feedback from PDO when a field name is wrong, but it doesn't seem to give that info.