Problems with login PHP script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
AlexKuhle
Forum Newbie
Posts: 6
Joined: Fri Mar 23, 2012 6:55 am

Problems with login PHP script

Post by AlexKuhle »

Hello everyone :-)

I am new to the forums, and it's nice to see that so many people are helping eachother!

I was following a guide on YouTube today, on how to create a login script in PHP, i have a problem tho.

I followed this guide -> http://www.youtube.com/watch?v=4oSCuEtxRK8

And i did EXACTLY everything he did, but...

At the end of his video, he logged in, and got a blank screen, which means he logged succesfully in, but all i get is this:

Notice: Undefined variable: username in C:\xampp\htdocs\xampp\Lowchat\login.php on line 6

And my script looks like this:

<?php

$usname = $_POST ['username'];
$password = $_POST['password'];

if ($username&&$password) - THIS IS LINE 6
{

$connect = mysql_connect("localhost","root","lol123","") or die("I could not connect to the MYSQL database!");
mysql_select_db('phplogin') or die("Could not find the database");

}
else
die();

?>

What is wrong with my script here :-S?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Problems with login PHP script

Post by Celauran »

You define $usname then try to use $username in a comparison.
AlexKuhle
Forum Newbie
Posts: 6
Joined: Fri Mar 23, 2012 6:55 am

Re: Problems with login PHP script

Post by AlexKuhle »

Wow i'm a dork, thanks alot man! :-X <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span> i feel stupid!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Problems with login PHP script

Post by califdon »

Don't feel embarrassed. That's what these forums are for. We've ALL made such oversights, probably MANY times. When you've written something yourself, it is very common to read what you think you wrote instead of what's really right there on the screen. Instead of feeling bad, use such revelations to remind you that you must always look carefully for just such errors when you are having trouble identifying why you get an error message. The best advice I ever got was from an instructor who told us that the 2 most important rules of programming are:
  1. Everything Matters; and
  2. Never Give Up!
AlexKuhle
Forum Newbie
Posts: 6
Joined: Fri Mar 23, 2012 6:55 am

Re: Problems with login PHP script

Post by AlexKuhle »

Thanks for the kind words califdon, and i will not give up, i gave up on PHP before, but now, i WILL win!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Problems with login PHP script

Post by califdon »

One tip that should come in handy:

Whenever you get an error message that says: "Notice: Undefined variable: username in C:\xampp\htdocs\xampp\Lowchat\login.php on line 6", it always means one and only one thing: YOU DIDN'T DEFINE THE VARIABLE that it names, but you're asking PHP to use it. Of course, it can't, which is exactly why it tells you the exact name of the variable it is choking on and the line number where you are asking it to use it. Remember, error messages are your friends.
Post Reply