PHP OOP Login/Register System: Update Information (Part 20/23)

preview_player
Показать описание

Official site

Twitter
Рекомендации по теме
Комментарии
Автор

heared your voice after couple of years man. I feel like I missed ya xD 

RomanBehroz
Автор

This is a good example how powerfull oop is!

SmellGreenLP
Автор

9:00 We got a big problem here ! Got the solution after a few hours !!!
DB update instance is failing if no id is specified. To solve this just go in User.php class and check the if(!user) { ... } added in lesson 17 (minute 3 second 20). So go to the else section and type $this->_is_logged_in = true;

Error in updating occurs because is_logged_in( ) was enabled only if user was not set !!

Tuttigiu
Автор

The DB is updating the name correctly. But Im still getting this message. And it never redirects. I could remove the ! but that doesn't feel like a fix it just a cheap workaround. Please help.

if(!$this->_db->update('users', $id, $fields)){
throw new Exception('There was a Problem updating.');
}

HappyDemon
Автор

One should always *escape output*, unless there is a (very) special reason not to.

This includes escaping your token, the messages from exceptions and the errors as (especially the latter two) they can potentially contain user data (which should not be trusted).

And yes, even escape the token (do not trust your own data either). This saves you the trouble to evaluate each and every case ("Do I need to escape this?") with the potential risk you miss an instance or misjudge whether it should have been escaped. Just escape it always by default.

Data in the database is not to be trusted (by default) either. Just because it passed validation rules does not mean it is "safe" (cannot break stuff). When outputting data from the database the same rule applies: unless you have a special reason not to escape it, _do_ escape it.

fml
Автор

When I try to update my details I getting logged out, anyone got a fix or same problem?

bingobob
Автор

Warning:

This method allows you to update your username to any other existing username registered in the database.

If there is an user with the name of "Maria" and you're trying to register an account with the same name, you'll receive an error saying that the user already exists.

If you register an account with a random name and then update it to be "Maria", the script will process it without verifying if there is any other existing name in the database.

MuffinologyTrainer
Автор

if you want to use two inputs one for firstname and lastname then when inserting just use a variable and concat the input values to save the name as input::get('firstname') .' '.input::get('lastname') then when updating you can have a $name variable and explode by the space and output into each field firstname value => $name[0] and lastname value => $name[1]

tylerobier
Автор

I can't get this particular thing to work. I'm not getting the name i have in the database in the field on the update page. The code i have in value is: "<?php echo escape($user->data()->name); ?>" but it still doesn't work. Also note that I've done this thing once before, so now i'm just rewriting ALL code to see if there is anything I fix that I wasn't able to last time, but I have the same problem now as then with this particular thing. Everything else works just fine.

adamastmar
Автор

I got the problem that every time i try to update my Name value it returns to me as :
name = ?

and it doesn't update in the Database

could anyone help me with this problem?

TheKamerlamp
Автор

I can't get to work in update.php! The Session::flash('home', 'Your details have been updated.'); will not be set when redirected to index.php? I have followed the tutorials from the very beginning and now this two things wont work? Can someone help me?

DamirCalusic
Автор

can anyone provide any information how this could be used to update something else I.e. an items title in a shop, please.

thehumbledeveloper
Автор

Hello. Again, very good explanation but I think we also validate for uniqueness. On the other hand, we should also check if the input value for name is changing or not. Because when we check for uniqueness, and the user does not change his name, we are getting a message like name should be unique.

ahmetozdemir
Автор

may anyone help me to understand the Token class and what does its functions do? 

ahmedtarek
Автор

I have no idea what I am doing wrong here. I have gone over the code about 6 times now. For some reason I can update my name in the database, but it is only passing in "0" no matter what I type in the input box it updates the record as "0"... any ideas?

Youcantguess
Автор

I am getting this error: Warning: Invalid argument supplied for foreach() in on line 13

vidakovicmiha
Автор

Okey, the code works and it updates the database. And it is still throwing an error.

yes i have the "!" infront. Would appreciate all help.

robinatorps
Автор

Can anyone help me with getting the register form and log in form on index page when the user is logged out and when is logged in to show content ? I can't get it working properly I don't know why

j.sleeka
Автор

Can anyone see anything wrong with this try/catch block? Been trying to sort it out but can't get it to do anything but throw up the error, even when it successfully changes the database.

if(Input::exists()) {
{
$validate = new Validate();
$validation = $validate->check($_POST, array(
'name' => array(
'required' => true,
'min' => 2,
'max' => 50
)
));

if($validation->passed()) {

try {
$user->update(array(
=> Input::get('name')
));

Session::flash('home', 'Your details have been updated.');


} catch(Exception $e) {
die($e->getMessage());
}

} else {
as $error) {
echo $error;
}
}
}
}

paulclarke
Автор

I am always getting the error message, and the database isn't updating anything... Anyone who can help me out?
The code for the update function:
public function update($fields = array(), $id = null) {

if(!$id && $this->isLoggedIn()) {
$id = $this->data()->user_id;
}

if(!$this->_db->update('users', $id, $fields)) {
throw new Exception('Der opstod et problem under opdateringen, beklager...');
}

}

TobiasBellingChristensen