Added: 3 years ago
From: phpacademy
Views: 149,383
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:
see all

All Comments (495)

Sign In or Sign Up now to post a comment!
  • why at 5:23 i get this error Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\XAMPP\htdocs\website\login.­php on line 13

    That user doesn't exist!

  • i was getting wrong password error, so i started over, and for some reason it work.............started over back from tutorial part 1 and it works,

  • The 1 is not appearing on my screen nothing happened like before

  • hey can you tell me how to transfer data from one page to multiple pages?

    ID from page1 to page2 to page3 and goes on........

  • rihanna's ass keeps distracting me!!

  • @fruitman89 hahahaha i agree

  • love these tutorials thank you!

  • hey why did u use a while loop??? Shouldnt the sql query return only 1 result

  • Hi, I made exacly what you did in the number 1, but it steel says:

    Not Found

    The requested URL /Web/login.php was not found on this server.

    What shoud I do?... I enter user name and everything and it's the same... please help

  • any tutorial for improving internet speed???

  • One thing though, if you are going to be using mysql_fetch_assoc then you need to free the memory using mysql_free_result afterwards. At least, it's good practice to do so.

  • This is the full working code for this tutorial. Part I

    <?php

    $username = $_POST['username'];

    $password =$_POST['password'];

    if ($username&&$password)

    { $connect = mysql_connect("localhost","roo­t","") or die ("cannot connect to the database"); mysql_select_db("phpalex") or die("Couldn't find db"); $query = mysql_query("SELECT * FROM user1 WHERE username='$username'"); $numrows = mysql_num_rows($query); if ($numrows!=0) {

  • Can anyone paste the full working code here?????

  • Comment removed

  • How come you're checking the username held in the database? This seems wasteful as we already know it

  • @FlamingTorch9 what if someone has not signed up? and they put a username in that doesn't exist in the db?

  • @getupkid203 I guess so

  • @FlamingTorch9 Maybe I am misunderstandig your question but the whole point is that you have a username inside a database that no one except for the owner of the database can view. What you are doing is, you are comparing what a user entered as a username on a form against what is in the database, if they are equal AND the password is correct as well than the user is granted access.

  • Please help me, it doesn't show up *that username doesn't exist* if I enter an username that doesn't exist, it's showing nothing instead. Help? Please!!

  • mysql_num_rows() expects parameter 1 to be resource.

    what does this mean?

  • @PellyTravispell I just had the errormessage too and found out that I made a mistake. Check if you have username = '$username'. That fixed mine.

  • Hi Alex,

    I've created a login and a register form but I've two errors:

    1. A user can login even though is not registered;

    2. A user can register whit the same data more then once;

    I save the data to a text file. I'm new to php and I would like you to help me out with my problems.

    Hope you can help.

    Thanks Mrwebmf.

  • @MrWebmf As for the user being able to register more than once on the same name, you should add a uniqueness constraint on the username field inside your table. Just head over to phpmyadmin, go to the proper table and execute this piece of SQL code (under the SQL tab you can enter code):

    alter table nameoftable

    add unique(usernamefieldhere);

    I recommend you empty your table first though...

  • Comment removed

  • Warning: mysql_num_rows() expects parameter 1 to be resource, string given in C:\xampp\htdocs\check_login.ph­p on line 17

    I don't understand where i have gone wrong :(

  • This helped me get my head around my uni work, of course I can't copy this but it helped a lot. Thanks dude

  • Hello, Thanks for very good tutorials.

    I was wondering where did you get $dbusername and $dbpassword in the code bellow

    ==============================­======

    while ($row =mysql_fatch_assoc($query))

    {

    $dbusername = $row('username');

    $dbpassword = $row('password');

    }

    Are they a new varialbles you just created or you alraedy had in the page somewhere.

    Thanks

  • @RezanKara They are a new variables

  • @RezanKara Im pretty sure they are new.

  • slight lag in sound and vid :D

    anyway. Great tutorials. 

  • What does this mean?:

    Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\member\login.p­hp on line 13

  • I can't login using my password, unless i entered the decrypted password with the ID.

  • Encryption? Security of database login? Do you have a video to revise this code using best practices?

  • hey when i do the query for numrows i dont get a number even when i have echo $numrows; could u plz help

  • @jgile2 Check to see if your variable was $numrows or $numrow, keep it consistent throughout your code.

    at least...that was my problem...

  • I keep getting the error "Undefined variable: numrows in C:\xampp\htdocs\loginsession\l­ogin.php "

  • @SodaWizard figured it out =)

  • help Parse error: syntax error, unexpected T_VARIABLE in /home/********/public_html/log­in.php line 11. can't figure out how to fix it. $query = mysql_query("SELECT * FROM users WHERE username='$username'");

  • Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/gabriel1/public_html/php­-page/login.php on line 28 it mean in line after if($username==$dbusername||$pa­­ssword==$dbpassword)  { echo "You'r in!" } how fix it?????

  • What is a query ?

  • IF YOU KEEP GETTING INCORRECT PASSWORD DO THIS -

    change: if($username==$dbusername&&$pa­ssword==$dbpassword)

    to: if($username==$dbusername||$pa­ssword==$dbpassword)

    It should work, give this a like! :)

  • @rainbowcrak Tyvm sir.

  • @rainbowcrak no need to do that because, the || means or we want && we must make sure that both match, you cant have it saying username or just the pass matches its cool, must be both, make sure you don't have an ; in the while, i had that then got rid of it and that fixed it for me mate.

  • Comment removed

  • Comment removed

  • I want the Numrows for the register script to check "user always exist"

    But i make that so:

    if ($register_submit)

    { include './../include/mysql_connect.ph­p'; $register_query = mysql_query("SELECT * FROM bsp WHERE name='$register_name'") or die ("ERROR"); $register_numrows = mysql_num_rows($register_query­); echo $register_query;

    if ($register_numrows!=0)

    {

    }

    I become allways the or die error.. :/

    WHY?

    Thank you!

  • awesome tutorials! thanks!

  • what's the point of while loop, according to php site about fetch assoc: If you're expecting just one row, no need to use a loop

  • on the first step where i should get number 1 i get resource ID 41

  • Comment removed

  • @j7512 me too

  • My error about the Incorrect Password was

    I had: "$dbusername == $row ['username'];"

    It should be $dbusername = $row ['username'];

    so "==" versus "="

    well...

  • I hate youtube ads!!!! im trying to learn :(

  • @onebighoe Learn to bypass, fucking.

  • @onebighoe Just install adblock plus.

  • $username = $_POST['username'] ; $password = $_POST['password'] ; if($username&&$password) { $connect = mysql_connect('localhost','roo­t','Rtyuio0') or die("couldn't connect"); mysql_select_db('website') or die("couldn't find db") ; $query = mysql_query("SELECT password FROM users WHERE username='$username'&&password­='$password'") or die('wrong password or username') ; echo "$query" ; } else die("please enter username and password") ;
  • wen i have the query of xBrandonMatthew93 i get the message: Resource id #4

    when i used echo "$query"

    can someone pleaz help?

    btw i get this also when i type a wrong username and password

  • @TM8Eyla this is script:

    $query = mysql_query("SELECT password FROM users WHERE username='$username'&&password­='$password'") or die('wrong password or username') ;

    echo "$query" ;

  • Comment removed

  • Ok I fixed it.

    I recommend Googling your errors to find out what your errors mean. Mine turned out to be a query error. Turns out the rows I had named within phpmyadmin were not the same as those I'd specified in my login.php document. Works a charm now, thank you!

  • I've kind of realised that it's comparing my username to that in the database but not my password. I use the code provided by xBrandonMatthew93, even changing the && to AND. Still no luck. but if I take out the $password == $dbpassword it works fine.

    Compares the usernames but not password. Any Help????

  • I'm getting the incorrect password part upon entering the correct password for my user. I've tried on both through xampp and my actual site. Neither has worked. I'm running a mac os x operating system on a macbook pro. Any ideas?

  • thanks very useful!

  • Excellent tutorial. Thanks :)

  • my god... just maximise your screen it would make it SOOOOOOOO much easier to make sure ive set everything up right im getting errors because you just go { } { } {} { } { }{{ {}{ } so its hard to see if ive done too many or not
  • What is the sign that yo used in the minute 0:55 in the part of query?

  • awesome tutorial you actually your are the first one who taught me how to write mysql statements because no one else had good enough tutorials

  • you are the best maaaaan for ever :)

  • givemeurmoney or die;

    yougotaletter;

    post;

  • @phpacademy hey i always get this warning when trying to add the numrows variable (Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\phptests\login­.php on line 13) i cant figure it out

  • @PellyTravispell have you worked it out?

  • @PellyTravispell change the numrows line to

    $num_rows = $result->num_rows;

    and itl work

  • @PellyTravispell $query = SELECT * FROM users WHERE username='$username evaluates to TRUE which is a boolean. Therefore $query is now 1 or TRUE This is because you entered the username correctly and since there is only one row in your database, a.k.a. one user. What MIGTH fix this is adding another row to your database, but I am not sure, I can see though that

  • @Fangornmmc Scrap that I see you already fixed it, well at least I got the source of the error right....

  • @the best

  • IT KEEPS SAYING "INCORRECT PASSWORD" When the password is correct

    ALEX!!!!! HELP

  • @xBrandonMatthew93 Read the comments... I got that problem but resolved it by updating PHP version.Or simply upload it to your online host which is what i did so you don't have to update your computers PHP version.

  • @flappajak i updated the phpmyadmin and still not working

  • @flappajak i updated phpmyadmin and still not working

  • @xBrandonMatthew93 Hmm, check your code and if it still doesn't work upload your files to phpmyadmin on your host instead of using xamp. I did that and it went away.

  • Comment removed

  • It always says incorrect password.

    I coded everything the same but it says the no password error so im guessing it isn't connection to db properly?

  • @flappajak are you making the password a md5 hash? if yes, go to db and check if the password field is limited to 32 characters, and you prob want to use varchar

  • @Swippz i don't have md5 just what alex wrote.

    My tables are varchars and are limited to 25 characters.

    I am using xamp.

  • @Swippz Nevermind, it was because my php version wasn't up to date :O

  • @flappajak lol, been there to, i coded something when i found out that my server was up to date, where a function was removed, it was some proxy stuff i was making tho

  • @Swippz This is what i made in 2 days of PHP work socialize.comoj(dot)com

  • @flappajak and? its not about who creates the most, its about learning while you write it.

  • I did that and nothing shows up if the password is wrong or if the username and password are right.

  • instead of doing ................

    $query = mysql_query("SELECT * FROM users WHERE username='$username

    Just Do..........

    $query = mysql_query("SELECT * FROM users WHERE username='$username&&password=­'$password'");

    Now it will cover both username and password

  • @xBrandonMatthew93 Scratch That nevermind

  • @xBrandonMatthew93 Yeah, wouldn't that be easier? I wonder why he doesn't do it that way.

  • its not working when i click submit button it only show/display the query or source code for login.php help me pls.

  • @jhenickoraine12 you need to install php and/or move your php files into the web server folders

  • Why do you need a WHILE loop here in the first place? You should only get ONE valid match of password and username from the query anyway. I removed WHILE from my code and it still works fine. Or am I missing something?

  • didn't understand the while loop !

    

  • Comment removed

  • if ($numrows!=0)

    { while ($row = mysql_fetch_assoc($query)) { $dbusername = $row['username']; $dbpassword = $row['password']; }

    if ($username==$dbusername&&$pass­word==$dbpassword) { echo "Successfully logged-in!"; } else echo "Incorrect username or password"; //whats wrong with my code...im not sure what im doing wrong? pls help!!! Thanks

  • @jerlui20 If you tell me what error it gives you i'd be happy to help m8

  • thank you very much.

    i liked a lot your explanations.

    i'm not english fluent but i can understand you very well

    because your speak clearly.

  • @heber288 its because otherwise there are always 12 yr old todlers spitting in the mic with a lowvolume of "Let the bodies hit tha flo!"

  • This is not the best way of doing it but it gets you up and running

  • what us wrong with this code:

    while ($row = mysql_fetch_assoc($query)); { $dbusername = $row['username']; $dbpassword = $row['password']; } //check to see if they match if ($username==$dbusername&&$pass­word==$dbpassword) { echo "you're in!" } else echo "incorrect password!";

    }

    else die("That user doesnt exist");

    }

    else die("Please enter username and password!");

    ?>

    this code doesnt show an error message

  • @maxxieboy95: remove Semi column end of while( );

    while ($row = mysql_fetch_assoc($query));<<<­<<<<<<

  • @maxxieboy95 You've got a semi-colon after your "while" loop and you need a semi-colon after your echo "your in!".

  • @Rous6026nz no cemi-colon needed after your in because semi-colons are line breaks for a new line of code to be separated from the next and since there is no more lines of code inside that function a line break(semi-colon) is not needed.

  • Comment removed

  • why my numrows == 0 ?? ;xx

  • II NEED U R PAGE

  • @csyicker my comment was wrong, I wrote stuff out wrong sorry <3

  • When I login the password is right, and email/username, it says the password is wrong, when it's all right :\.

  • Hey guys, For some reason the "Wrong password" won't come up when i do wrong password, I'm willing to pay someone 1 dollar to help me fix it, I copied his whole code right but it won't say wrong password.

  • after login in this message shows

    Notice: Undefined index: username in C:\xampp\htdocs\sitea\login.ph­p on line 11

    Notice: Undefined index: password in C:\xampp\htdocs\sitea\login.ph­p on line 12

    Please Enter a username and a password

    ------------------------------­--------------

    pls help me fix this..thanks a lot

  • Comment removed

  • nice tutorial, but make it slower for the beginners

  • Comment removed

  • 05:32 "And my password is aaaaabc" - INVALID PASSWORD :D

  • WHEN I FINISHED THE CODE, I BLAMED ALL MY MISTAKES ON YOU.

    I HAD ABOUT 20 TYPOS and an INCORRECT LOCALHOST PASSWORD.

    EVERYONE PLEASE SPELL CHECK YOUR CODE WITH CONTEXT NOT NOTEPAD ++, OR SPELL CHECK WITH DREAMWEAVER.

    IN ADDITION, IF YOU NEED THE FULL CODE, PM ME, i WILL HAPPILY GIVE IT TO YOU, PEACE.

    PHP ACADEMY, THANKYOU FOR YOUR TIME.

  • Whats wrong with my code? I have the same code as in the video. But my DreamViewer shows theres an error on line 28. In web it shows ''Parse error: syntax error, unexpected '}', expecting ',' or ';' in /home/mehisunri/domains/mehis.­unri.lv/public_html/regtest/lo­gin.php on line 28''

  • So, can anyone share with the rest how we can get over the "Incorrect password!" part? I can't seem to find a solution anywhere. Removing the while statement does not fix it, as some have pointed. Plus, I've been getting Undefined index: $username as well as $password notices, which if fixed may or may not lead to fixing the "Incorrect password!" part aswell. Anyone? :|

  • I found my error. Instead of $dbusername = $row['username']; , I had $dbusername = $row['$username']; . Same thing with the password. How silly of me :P Still, I'd like to know of a proper fix for the notices instead of just turing them off when the page is 100% ready.

  • hi , why that block with mysql_fetch_assoc must be in while loop? thx

  • Can you please put it on 4shared or somethin like that. So we can just copy the text. Cuz I understand everything you say, but there is somethin wrong in my code, cuz when Im at the mysql_fetch_assoc part, and follow what you do, I probably made a mistake, but I checked like 100 times what I did wrong. When I test my script it says it has an syntax error. Please help me, cuz your lessons/tutz are great! But Im hopeless now. Sorry for bad English, Im Dutch.

  • @grkgerman100 If you run ubuntu open terminal and basically use this to get your answer if running (You)su Password: (if it worked it should say root) /opt/lampp/lampp start so owner@owner-Inspiron-537:~$ su Password: root@owner-Inspiron-537:/home/­owner# /opt/lampp/lampp start Starting XAMPP for Linux 1.7.4... XAMPP: XAMPP-Apache is already running. XAMPP: XAMPP-MySQL is already running. XAMPP: XAMPP-ProFTPD is already running. XAMPP for Linux started.
  • Notice: Undefined variable: dbpassowrd in C:\xampp\htdocs\asd\login.php on line 24

    if ("$password"=="$dbpassowrd" && $username==$dbusername)

    What is wrong with this? :|

  • @xDstefan100 $password and $dbpassword shouldn´t be in qoutes

    That´s all...

  • Comment removed

  • You can add checks like this to improve security. you should also add this check in the registration page.

    // If the username does not contains letters or numbers, gives a error.

    if (!ctype_alnum($username)

    { die("Invalid username."); }

  • Why do you need to check if the username in the DB is that same as the one you've put in? With the query you've written, any row you get is guarranted to have the same username as the one you've put in.

  • I keep getting the "Couldn't find db" error when I run it. I can't figure out why. I feel like it's something simple.

  • @154Rambo If you are using xampp, is your MySql running? I get the error when it's not.

  • Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'root'@'localhost' (using password: YES) in C:\xampp\htdocs\xampp\login.ph­p on line 11

    Couldn't connect to database

    I get this error any idea how to fix this?

  • @FlipjuhhPlox Your username / password to connect to your database is invalid.

  • @FlipjuhhPlox XAMPP default setting has a empty password, use $dbpass = ""

  • I enter my true password but it says " Incorrect password ! "

    Any help ?

  • dunno if you do this but you should use the trim function like this trim($_POST['username']) as just spaces are accepted otherwise.

  • How do I put everything on localhost? :)

  • on my code when i go to try the numrows it says the echo "Please Enter and username and a password" i doesnt show me a 1 it shows me the echo... any help will be apprechated....

  • $username = mysql_real_escape_string($_POS­T['username'])

    use this people, against injections.

    Also put an md5 on the $password

  • @ZTOID considering this will not be echoed it doesn't matter and only use md5 on the password if the one in the database is md5'd

  • Comment removed

  • Whenever I click submit on my login thing it just downloads the php file

    

  • @TechWeKnow You dont have apache installed.

  • @TechWeKnow

    Open it with Firefox.

  • Thank you for the wonderful tutorials. But the tutorials a bit too fast for me to grasp

  • I thank you on the behalf of 100 students that need to finish their web projects!

  • Hello to all.Very nice tutorials man.I have some problem with my log in page in my site and if you want to help me i will appreciate that.I woke in the morning and tried to log in but always says invalid password without changing.I have two log in users i delete one account from the database and recreate it,but when i try to log in always appears a message and says "You must have the proper credentials to access this page. Please login."What i did wrong?what should i do??please help :-(

  • Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\login.php on line 16

    that user doesn't exitts when i enter correct username and password.its say user doesnt exits.plz help me

  • @bikenb1 ive got the same problem

  • @bikenb1 try checking all ur spell

  • my loginphp keeps blank what did i do wrong

  • try in the if statement md5('$password') ) and not md5($password)

  • It says my password is incorrect no matter what. I have scanned over that code over ten times in depth..I can't figure out the problem..any suggestions?

  • how do i insert input string like üñá into the database..this is converted into something else!! Plz Help me!!

  • Hy there !

    Could you tel me what commands shall I use to encrypt my password in the login page, if I used md5 for the registration ?

    Sorry for my english .__.

  • @TheKristofer999 you just put an .md5 and it auto ancrypt's it

  • @62arts And to where?? O.o

    Before the fetch assoc line, or after it, or to the very beginning of the script ?

    Sry I'm a newbie :D

  • Hi i need some help here

    Notice: Undefined variable: numrows in C:\xampp\htdocs\login.php on line 17

    That user dosent't exist!

    i already check 100 time i can't see the error on this

    please help!

  • PHP Error Message

    Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at 'reading initial communication packet', system error: 113 in /home/a5977309/public_html/log­in/login.php on line 9

    Free Web Hosting

    Couldn't Connect!

  • i cant connect to myphpadmin

  • No matter what password I use it always says I'm logged in heh'.

  • I get a Notice: Undefined index: password when doing the while loop

  • when i do any code it says "Parse error: syntax error, unexpected $end in C:\xampp\htdocs\login.php on line 23" plz help

  • @wheatthin0005 Send me the lines 20-24 via message or answer here!

  • he typed down "Please enter and username and password" lol

  • I've run into a problem. My problem is with the mysql_num_rows(), when i do that just as in this tutorial, I get an error: "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\bla\bla\Login.php on line 12" Anyone knows how to fix this?

  • why i always get user does not exist error. omg

  • Great, thanks!

    Mysql injection would work on this, wouldn't it?? I think there is a built in php function that prevents that?