PHP Tutorials: Register & Login (Part 7): User Data (Part 2)

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

Official site

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

Neat implementation Alex. You are forcing us to be good programmers! Thanks mate.

JasonRodrigues
Автор

Initially I had the same problem but solved it now. Check whether the sql returns the expected data from the table. mysql_fetch_assoc() returns a boolean if the SQL query fails. If the mysql_fetch_assoc returns FALSE which is assigned to $data (an array by our definition) the resource and boolean conflict arises.
Alex, thanks for your wonderful videos.

newstien
Автор

I love these tutorials, you are a fantastic teacher. My only wish is that you were using PDO when making them.

MyIrishWhiskey
Автор

Another GREAT tutorial. It's not the most simple way but maybe the best way.

AlexandreSk
Автор

Man, now it's so easy to keep track of things! Thank you so much for this, my code was getting a little messy so I decided to start fresh. Thanks again! :)

toms
Автор

Alex, You're awesome !! thanks for your helpful tutorials =D

obalfaqih
Автор

You don't actually have to user backticks, you can leave them out completely. Use single quotation marks when you are writing the value of a string in mysql, but you don't need to use backticks around the database, table or column names.

gfloodsie
Автор

I see quite a few are having the 'mysql_fetch_assoc() expects parameter to be 1, boolean given' error and nobody gave an answer as to how to fix it.

Just simply remove the single quotation marks ' ' from 'users' and 'user_id' in that line. Or just copy paste this between the parantheses: "SELECT $fields FROM users WHERE user_id = $user_id"

Please thumb up so people can see.

brucewayne
Автор

Awesome, this was exactly the solution! Adding this to my bag of tricks!

KarlozWatson
Автор

It's the simple mistakes that are sometimes the most difficult to catch! One simple unintentional character can leave you scratching your head for hours on end later.

gfloodsie
Автор

Thanks Robert Ames
I am going to restart the entire tutorial and, i will keep your suggestion in mind.

prashjad
Автор

You should always be using prepared statements in your queries to prevent sql injection.

nlytnmnt
Автор

It probably will, but for that many users you will need a lot of security measures in place for that many users.

tonythedemon
Автор

go to init.php and make sure that the row names (from your table) are an exact match. For example: 'username', 'password' ...and so on must be the same as the names you see in your database (look in myphpAdmin). Then make sure you replicated the same in users.php.

jlawass
Автор

Same here dude, Alex has the users lastname as lastname however i had it as surname. Easy mistake to make but if you take the easy way out here, you will regret it later :)

paulmcneice
Автор

I've made a few changes to get mine to work properly here they are and I hope they work for you.

1. Change the SELECT $fields to SELECT *

$data = * FROM `users` WHERE `user_id` = '$user_id'"));

2. Make implode function a comment just to save it if you needed to use it later by adding //

// $fields = '`' . implode('`, `', $func_get_args) . '`';

3. When calling the user data in init.php take out the ' ' marks

echo $user_data[username];

Works up to 3:46

robertames
Автор

No problem...the implode should actually work but for some reason it doesn't want to...I still haven't figured out why exactly, but I'll look into it.

robertames
Автор

@phpacademy my favorite color is 10 :D

stamtheodmusic
Автор

THANKS A LOT, U are my hero...
have fun :)

kasske
Автор

Take the backticks out, like so;

$fields = '' . implode(', ', $func_get_args) . '';
$data = $fields FROM users where user_id = $user_id"));

and it'll run for you, mate.

Volvagia
join shbcf.ru