Added: 2 years ago
From: phpacademy
Views: 76,313
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:
see all

All Comments (292)

Sign In or Sign Up now to post a comment!
  • So, anybody know what code I could add to check user registration info against the info in the database and not let them re-register?

    I would guess after the

    $connect mysql_connect();

    that this might be the next line of code

    $connect = mysql_query("SELECT * FROM users WHERE email='$email'");

    then...

  • After hours of frustration, I finally figured out that I haven't declared the $connect variable or the $queryreg in my script. I'm guessing this is why my info won't post into the database account. Correct? How do I declare these variables, like I declared the $username and $password etc, at the top of the script?

  • @just01161

    $connect = mysql_connet(" "," "," ") or die ("Couldn't Connect!);

    mysql_select_db (" ") or die ("Couldn't find Database!");

    $queryreg = mysql_query("INSERT INTO users VALUES ('','$fullname','$username','$­password','$repeatpassword','d­ate')");

  • @just01161 Do I need to add periods around them like the lower post? '.$username.'

  • @just01161 my code does have the c in "mysql_connect" lol that's not the problem

  • @just01161 ha, I just got it to work. Great tutorial, learned soo, soo, much. Thanks!!

  • aa

  • It works!

  • $queryreg = mysql_query('INSERT INTO users(name,username,password,d­ate) VALUES("'.$fullname.'","'.$use­rname.'","'.$password.'","'.$d­ate.'")', $connect);

  • Comment removed

  • Comment removed

  • I looked around and found this:

    $queryreg = mysql_query ("INSERT INTO users SET id='',Name='$fullname',usernam­e='$username',password='$passw­ord',date='$date'");

    It works now.

  • - we should also use my_real_escape_string() for any entry

    - He should check if username does not exists in the database before he inserts a newuser otherwise registered username can be taken even if it already exists.

    - I do not want to continue with the errors.. because I do not want to discourage anyone for reading these tutorials

  • $sql = "insert into users (`id`, `name`, `username`, `password`, `date`) values ('', '$fullname', '$username', '$password', '$date')";

    mysql_query($sql); at register.php

    $username = (isset($_POST['username']) ? $_POST['username'] : false);

    $password = (isset($_POST['password']) ? md5($_POST['password']) : false);

    at login.php have to md5 the password

    phpmyadmin: password varchar(32) because md5 changes anything to 32 characters

    then it should work.

    

  • Somone Plz help!

    I have everything setup, but when i went to sign up it said this:

    Notice: Undefined variable: connect in C:\xampp\htdocs\test_website\r­egister.php on line 38

    Fatal error: Function name must be a string in C:\xampp\htdocs\test_website\r­egister.php on line 38

  • i couldnt save the data in the database ,, i read all comments and i did many changes and also the same ,,, i dont know what to do uff :(

  • Alex, you're doing an awesome job! Watching videos like this makes me want to disconnected cable TV :).

    I notice people are having issues with inserting data to the database here is a hint for those that cant get it. mysqlquery("insert into table(id,fullname) values('',$fullname)")

    good luck, hope this helps!

  • I just finished writing all the tutorial and tested it with xampp and works like a charm. If you want the files PM and i will give you.

  • can you email the code no matter what i do i can't get it right

  • Hmm still can't seem to get the user information to submit to the data table....

  • i have problem with the date :( it only says 0000-00-00. how stup is that

  • hey i have a brilliant idea of how to make this much easier....email me the codes :/

  • Hmm, i keep getting the message "Password must be between 6 and 25 character" even when they are over 6 characters

  • Why I follow all steps as movie. But cannot move data into mysql???

    HELP!!!!!!!!!!

  • i did everything right but when i insert data and click on register it process alright. but nothing transferred into my database. it add's one raw and my details are not in it. error message

    Notice: Undefined index: submit / fullname/ username / password/ repeatpassword. plz advise.

  • I have a proble. It says that I registered successfully but I can't see user in my datebase. Any help? I can send you my code too to check if there is any mistake.

  • @aleksy36 im still only new to PHP, but after following every step that Alex has shown us, it worked perfectly for me. Whilst watching the tutorial and reading your post, I thought that maybe the mysql_query that Alex had written was incorrect, but on second inspection its spot on...maybe go through it all again with a fine tooth comb and double check your code...there may be one tiny little character out of place...good luck :)

  • everytime I type in any information in register.php it says that passwords do not match. where did I make a mistake? I can send you a PHP code if you need it.

  • can you give the template?

  • I keep getting the "Incorrect password" page which we created. Its an 'else' in the 'login.php' page. Any help?

  • Why is is when I press enter after filling out the form is offers me to download my register.php page.

  • Hello everyone if anyone got notice errors in their text fields while doing this form validation procedure of when alex does value=the php code i figured out how to make it work in the browsers.The code is just like what alex has but i cant post it here if you want the code please send me a email on youtube requesting it.thanks..

  • aaaah i dont understand the html form value php script thing that alex phpacadamy did in this tutorial can someone plz send me the script or help me with the code please or send me mail in my inbox. i keep getting erros in my textboxes in my form what am i doing wrong.

    thanks

  • @025JoshTMMM82 use error_reporting(0); after the first <?php tag.. IT works for me..

  • @025JoshTMMM82 Putting the codes inside the value of the html means, that when a person for example fills all forms like username, fullname and password,and ...say if he entered the incorrect password.. when the page refreshs to inform him about the incorrect password entered the browser will store and keep the username, and full name to save you time from writing it again. For that effect, you must right the variable of the username inside the value of the html.i am so newbee knew that recently

  • Hello everyone,

    I have had a bit of trouble with the coding on this part, with no fault to Alex (thank you very much by the way), but with the syntax of all the lines put together.

    With so many if statements, you really have to make sure you understand what is being done if requirements are met and when they are not

    I would also suggest downloading that text program he is using. ConTEXT is actually a great tool to diagnose any problems because it colors everything in an easy to understand way.

  • Hello Alex,

    I need help Its when he putted the echos in the html fields but has anyone gotten this error message into their textbox or box yet of html code saying Notice Undefined Variable: fullname or username or something like this Notice: Undefined variable: firstname in C:\xampp\htdocs\register.php on line 77 has anyone came across this yet please let me know by sending me email on youtube. thanks. it has like bold and breaks in html code

  • Seriously can you just post the code? I've wasted 5 hours of my life on this I think

  • Here is a big hint for all you having trouble with the error message "Undefined index:"

    if(isset($username)){echo $username;}

    the function isset(); takes a variable and returns a boolean value 1(if value is not null) 0(if value is null)

  • @smokenfly514 He wants you to LEARN the code, not just to copy/paste!

  • @JDTuts you can learn without having to follow a step-by-step tutorial.. programming is logical; you can learn syntax and how everything works by simply reading the code over many times and trying to copy it

  • @smokenfly514 yeah if you think so you should just dump learning php .. the point is to see how it is done not to get the code - there are many done script on the web .. GTFO ! great tutorial !

  • @elpazzobg If one is familiar with the basic important programming concepts, one may learn a language by being provided with the code, understanding what it does, and then going over the syntax and logic. It's retyping the code several types that is key. Your comment merely demonstrates your lack of intelligence. And for the record, I'm way past this and learning at a faster pace than you with my method. You're dismissed.. and don't bother replying because I won't read your response.

  • @smokenfly514 you did not waste, you learned. 

  • @kirillosk No. I learned elsewhere.

  • noob alex!

    answer in our questions or delete the video!

  • I'm having a problem with my register.php

    Here's the paste: pastebin (DOT) com/NUMygB9m

    ---it keeps saying---

    Notice: Undefined index: submit in E:\xampp\htdocs\lesson\registe­r.php on line 3

  • DATA WASN'T INPUT FIX:

    if everything looked good but the data wasn't input into the database, for me it needed two fixes:

    1. in your database, the varchar of password should have a length of 32 or greater

    2. Something must be input into the mysql_query line (for me at least)... Changing the user id from '' to 0 (or any number) fixed it for me, that is... VALUES ('','$username','$password','$­fullname','$date') ");

    changed to VALUES (0,'$username','$password','$f­ullname','$date') ");

  • u are right :p but what I was trying to say is since we add the md5 encryption of our password in the database (of length 32 btw) and not our password(of length 25) our varchar needs to be 32 of length at least to make space for the md5. so if it says that uve been registered, but it DIDNT add to db, means that your codes good, only there is no space in your varchar for the md5 version, so change it to 32. If it says that password is too long, means u did md5 b4 checking length, so u checked md5

  • Hey guys just a heads-up, I've noticed that if you follow this tutorial step-by-step, it allows for duplicate usernames. If you want your users to have unique usernames, you'll have to select "username" from the database and check the number of rows. If no values are returned, the registeree's username is valid. Then, you can proceed to adding them to the database.

  • Hi Alex like others have said can you post your complete code so I don't have too many {{{{{{{{{{{{{or }}}}}}}}}}}}}} as well as human errors?

  • Incorrect integer value: '' for column 'id' at row 1

  • thanks man,

    if you have 2 same registered user in the database then just remove md5($repeatpassword);

  • I would recommend using regular expressions rather than strlen. You can save a lot of room this way. For example:

    $check_name = preg_match('%^[a-zA-Z0-9\.\-]{­6,15}$%', stripslashes($username));

    do the same for password, then run a conditional to check if both of these values are true. This pretty much ruins any SQL Injection attempt.

  • I can't Insert my infos in the database.

  • These videos are awesome.  One problem on this one is that I am getting everything to the database, except the date, which shows all 0's. Did I miss something? Thanks!

  • Great tutorial Alex. We all appreciate your time

    Did anybody ever get this completely working?

    I am not.... Although, many of us are spening hours and days trying to get it working and in the process learning some PHP. I still think that we should see a complete working codes so we can see where we are going wrong.

    I am stuk with the md5 and perhaps more to come.

    Please post the codes

    Thanks

  • I'm getting addicted to your tuts

  • Comment removed

  • Comment removed

  • I just can say thanks for the tutorials you made. They are very useful and many webdesigners now can script :D because of you. God Bless you sir. :) (bow)

  • i keep getting an error

    about a unexpected { on line 25

  • Comment removed

  • Comment removed

  • the password longer than 25 problem is because hte password is encrypter before that check therefore the encryption is always more than 25

  • very nice tutorial..thanks man..lol i already done in my project..^^

  • Even after filling all the fields its saying please fill all fields.

    any one facing same prob.

  • oops sorry about that, didnt mean to put it up twice, my bad

  • I was brought to the page where it said i successfully registered, but the data wasnt in the database. I think it is because in the beginning, we put the varchar of the password to 25! but with the md5 encryption, our password variable ($password) is longer than 25.... so i changed to varchar length to 1000 and it works! Thumbs up so everyone can see :)

  • @XxLethalxStrikesxX you shouldve set md5($password) after your password check

    if (strlen($password)>16||strlen(­$password)<6) { echo "Password must be between 6 and 16 characters"; } else { //encrypt password $password = md5($password); $repeatpassword = md5($repeatpassword);

    //register the user echo "Congrats"; }

    Thumbs up so everyone can see the fixed version!

  • Comment removed

  • @XxLethalxStrikesxX it still don't work for me :(

  • @XxLethalxStrikesxX Md5 only needs a length of 32!

  • @XxLethalxStrikesxX Only needs to be 32. ALL MD5 hashes are 32 bits of data, more commonly known as 32 characters. If you have 1000 then you can run in to problems.

  • I was brought to the page where it said i successfully registered, but the data wasnt in the database. I think it is because in the beginning, we put the varchar of the password to 25! but with the mdy encryption, our password variable ($password) is longer than 25.... so i changed to varchar length to 1000 and it works! Thumbs up so everyone can see :)

  • still wont let you log in, simply because your password is hashed, but in other cases, onto the next one! :D

  • im done doing Login and Registration Tutorial with my database and it was successful, thank you PHPACADEMY, your the best..i'm from Philippines :))

  • is it possible to upload notepad file.

  • Hi, how do you view or retrieve the auto incremented id after the user have registered? like giving the user id to the registered user.

  • Wow thanks man!! It Works perfectly fine with me eventho my registration form is more vary

  • i get a notice in my box were i writhe fullname and username

    a notice that the variable fullname/username dont have a value

  • @flaggis97 me 2

  • how to get rid of the errors? Undefined index?

  • @sergyu123456

    Put @ beside the $ sign

  • you guys need to give more info when asking for help

  • HELP I just get all the time " Please fill in all the fields", what can be the problem?

  • i always get please fill in all fields but i do and nothing else shows up. please help

  • I don't get why it works when he does it. 100% sure you need to use an isset first!

  • So far, best php login and register tutorial i ever seen before

  • hmm date dosnt work for me, it comes up as 0000-00-00 in my database...

  • @daeheadshot maybe you tried some other date format instead of $date = date("Y-m-d"); (which i also tried at first, since I use d-m-y in my daily life) or didn't put '$date' in the sql_query

  • WTF. Where did you explain the code? I mean the code from the top. I dont saw it anywere.

  • By the way wtf with all people requesting for the code. Write your own code and learn!

  • I think that the use of a javascript for field verification should work a way better than querying the database each time the user posts invalid or wrong data. It saves bandwidth and server load IMHO.

  • Is it best to have your mysql_connect happen off the page in a folder outside of htmldocs or web?

  • Absolutely clear and well produced tutorials, Alex. Thanks so much. Really helps supplement my reading of the books to see someone putting all this together before my eyes. Excellent stuff. Subscribed!

  • please post the code .__.

  • Alex please can u put your register.php and login.php in the descripion because i have done this 2 now and i get an error with the validation.'s

  • Help I Just keep Getting Password must be between 6 and 25 characters long! When It Is

  • @MrKoolTutorials Watch the end of the tutorial he shows how to get around that

  • @mrwilson41 i fixed it ages ago any way soz

  • @MrKoolTutorials its because he ecrypted the passwords to md5 BEFORE he checked the length of the passwords(converting it to md5 creates a 32 char long string)

    just put the md5() inside the else body of the password length test

  • @MrKoolTutorials put md5 in the else of the password lenght test!

  • @MrKoolTutorials that's because he applies md5 before checking for the length of password! Just check the length first and then apply md5. It should work :)

  • @MrKoolTutorials Have you removed the md5 function on the top of the code?

  • @MrKoolTutorials Reorganize your code so that the script MD5 encrypts the password AFTER it checks for password length, not before. Your perfectly legitimate password is put through md5 and ends up like this: 5f4dcc3b5aa765d61d8327deb882cf­99, which is longer than 25 chars. Here is what is SHOULD look like: if (strlen($password)>25||strlen(­$password)<6) { echo "Username and password must be longer than 6 characters"; } else { md5($password); md5($repeatpassword); }
  • @MrKoolTutorials check your heirarchy of your if statements and go through them one at a time. be sure that they are all one after another until you are ready to register the user when everything is correct (in the middle of the if statements, before the user error messages that you put using else statements when the if statements are incorrect.) if you need more help i can pm you with what i have that works.

  • @MrKoolTutorials The reason your are getting this error is because Alex encrypted the password before checking for length. The length of md5 encrypted passwords is always 32 characters and that's why you get the error. To fix this just encrypt the passwords after you check for length.

  • Comment removed

  • @MrKoolTutorials

    You're getting the error because you are getting the length of the md5 encrypted version of the password, wich is 32 characters long. He only showed almost all of the ways to get an error message, but not how to get the succes message. You simply need to check the length of the non-md5 encrypted password :3

  • @MrKoolTutorials md5 NEEDS to be after password length check

  • @MrKoolTutorials If you've enrypted the password before it checks if it is between 6 and 25, than it's gonna say it's too long. Move that encryption md5 code above the code for storing datas in the database.

  • @SlobodanV1984 FUCKING HELL I FIXED IT AGES AGOAND I KNOW STOP SAYING IT!

  • @MrKoolTutorials fuck you

  • Comment removed

  • @MrKoolTutorials it's because he set the md5 to the password before controlling the length and your password is no longer 6char but something like 5h39038n23hrh. So you can set the md5 just at the final else statement or you can assign a new variable for the password variable.

  • @MrKoolTutorials Take the $password = md5($password); and $repeatpassword = md5($repeatpassword); strings and put them after echo "Success!!";

    Otherwise the passwords are automatically converted to md5 (and they are long) before they are even put in the data base. If you move it at the end, it will only convert them into md5 if all criteria have been met for a successful login.

    Sorry if it doesn't make sense. I'm a total beginner. But it worked for me.

  • Im also having the same issue. the page seems to be ok and says, registration is successful. but it's not inserting into my database. please help.

  • Could anybody post the full working code?

  • Hi all,first of all i'm an italian boy so sorry for my bad english xD. Thanks a lot for this great tutorial. It helped me so much. For everyone that have some problem with the querys i resolved with:

    $queryreg = mysql_query("INSERT INTO `users`(id, username, password, date) VALUES (NULL, '$fullname', '$username', '$password')");

    I hope that it will help you. Bye!

  • @IlPadrinoRulla THANK YOU SOOOO MUCH!!!!

  • even after typing the correct data into all the fields and clicking register..i donot get success...i keep gettin passwords donot match..any helppp...plssss...

  • When we check the password length, isn't it already md5 encrypted? In that case it will always be more than 25 chars long, am I right?

  • @buddhagoulash this is the problem I'm having...I get the 'password is too long' error message no matter how long my password is...any ideas why?

  • @buddhagoulash to fix this problem I had to encrypt the password after the strlen() check, in case others are having the same issue.

  • @buddhagoulash yes i found out why, its because of the md5() function changing the password too early in the form, that the $password becomes the "fdsgnkw4nwkfn20fekmwlef" or whatever, to fix this, simply add the md5() [or in my case, the hash('sha256')] right before you finish your form... for eg.

    ...} else{

    $password = hash('sha256', $password);

    $repeatpassword = hash('sha256', $repeatpassword); echo 'You have been successfully registered.';

    }

  • @buddhagoulash i think its cause it encrypts it to md5 beforehand wich means that it is looking at the encryption length, try adding the md5 encryption after you have gone through the check password length, hope it helps if not send me a message and ill try to find a fix for you

  • Comment removed

  • even i specify the fields of the database on the sql command, i still cannot save my data in my database. but i don't get errors. anyone?

  • Notice: Undefined index: fullname in C:\xampp\htdocs\xampp\aw\log in\login\register.php on line 7

    Notice: Undefined index: username in C:\xampp\htdocs\xampp\aw\log in\login\register.php on line 8

    Notice: Undefined index: password in C:\xampp\htdocs\xampp\aw\log in\login\register.php on line 9

    Notice: Undefined index: repeatpassword in C:\xampp\htdocs\xampp\aw\log in\login\register.php on line 10

    this is the error but the program works properly how do i remove that error

  • @killerboduk999 Hello, You need to use " if (isset('submit')) { /*all your coding defining variables*/ } hope this helps!!! :)

  • when i first click on the Register? link, some how the localhost/register.php shows this error:

    Notice: Undefined index: submit in C:\xampp\htdocs\loginsession\r­egister.php on line 5

    same goes to index: fullname, username,password, repeatpassword.

    can someone tell me how to fix this error?

  • Very clear and helpfull. Thanks

  • great tutorials. i think it would be helpful if you upload the .php documents so that we can compare our codes. the if and else statements here get very complex.

  • error on line 48 and 54

    using dreamwaver help please

    line 48=else

    line54=else

  • AWHHHHHHHHHHH, ffs, now none of the god damn check's work..

  • Comment removed

  • @PartyDoffy

    make sure you are not missing any ; or any ()

  • keep getting this error Parse error: syntax error, unexpected T_STRING on line 49

    (not always line 49)

    and i checked line 49(and other lines) and there is no error there..

    only way i can fix this is to write the whole script thing again

    already done it 4 times im getting sick of this

    please help

  • Im using phpMyAdmin 3.3.9.2 and mysql 5.0.92

    when i got

    Incorrect integer value: '' for column 'id' at row 1

    error from

    INSERT INTO users VALUES ('','$fullanme','$username','$­pw','$date')

    so i tried

    INSERT INTO users VALUES (null,'$fullanme','$username',­'$pw','$date'))

    then it works

  • Comment removed

  • My code keeps giving me that my passwords don't match... even if i put in the same passwords. If i don't put a user name it will give me that same error too. please help

  • @RS777able

    check if you forgot to put $ on your password variable

  • Please explain the full code in register.php because you started the video when testing the code.

  • @MrUpload1000

    subscribe the channel and watch the playlist. you will find what you are looking for

  • This is a life- saving tutorial. Thanks $Alex Garrett, &&$Murkata, &&$codyjd2010.

    And every that contribute to this tutorial. You are all the best.

    I am yet to figure out why somebody will dislike this tutorial. Probably they are reading from behind..

  • please speak slower and clearer - there are many people with foreign languages.... thanks. your tutorials are good....

  • I saw all the Tutorials, but i don't understand nothing :(((

  • Works fine for me. Thanks for the tutorial.

  • Wont send everything to the database.. I dont get any errors ether...

  • I keep getting Notice: Undefined index: password in C:\xampp\htdocs\Reg\register.p­hp on line 7 whenever i get out of the page and hit register again in the index.php page

  • can u post here the full codes for register.php.. coz it is not recognize in the video.. in short.. the "VIDEO" didnt start at the top.. he started immediately in testing the register.php.. thanks..

  • can u post here the full codes for register.php.. coz it is not recognize in the video.. in short.. the "VIDEO" didnt start at the top.. he started immediately in testing the register.php.. thanks..

  • ok well when i entered all my info into the form it didn't display the registration success or the link to the login page, it comes up with a blank page with the word Register on top. and it will not insert any data into my database!

  • every time i put in all my info and with a password with more than 6 characters, it says "password must be between 6 and 25 characters!".

  • sir in this lesson.do you have a field name confirm password in your database?

  • If you can't make the data adding to the DB make sure the variables you insert are in the correct order as in phpMyAdmin!

  • Ur php tutorials are the best !!!

  • Also, one more thing I've noticed - due to the md5 hashing the hashed password is more than 25 characters. I've increased the lenght of the password in myphpadmin to 40 and then it was working fine. Hope this helps.

  • @murkata86 I was about to post the same thing! Good call.

  • Hi All,

    I was having the same issue - no errors, but data wasn't added to the database. I've checked in Google and it seems that the data was not added becase MySQL was trying to put the data in rows, so I've adjusted the code telling MySQL to put the data in the columns. Here is how the new code:

    $queryreg = mysql_query("

    INSERT INTO users (name, username, password, date) VALUES ('$name','$username','$passwor­d','$date')");

  • @murkata86 how to put that code

  • still i cant connect on my data base i have a proble m on root

  • @murkata86

    I did this and it went into mysql but the password is just changed to d

    why??

  • @murkata86

    you're the best !!!!!!! i was trying to figure out what the hell was wrong until i saw your "beautiful" comment ..

  • @murkata86

    Hi, thank you for help! it´s working.

    I coldn´t insert data in mysql, you help was a sucess.

  • @murkata86

    thanks a lot man :D

  • @murkata86 thanks

  • Comment removed

  • Is anyone else getting an error on:

    if(strlen($password)>25||strle­n($password<6)

    {

    echo "Password must be between 6 and 25 characters";

    }

    On the } symbol ROFL

  • @MrPayDay123 Rofl fail I forgot the ) by $password