Hi guys! I have created a user registration system which works fine, but now im creating a login with the same database but i keep getting this error:

Notice: Undefined index: username in C:\wamp\www\PartyTime\Opening page.php on line 14
Notice: Undefined index: password in C:\wamp\www\PartyTime\Opening page.php on line 15

Ill post the code too so you can see whats going on:

$host=“localhost”; // Host name
$username=“nandu”; // Mysql username
$password=“nandu”; // Mysql password
$db_name=“registration”; // Database name
$tbl_name=“users”; // Table name

// Connect to server and select databse.
mysql_connect("$host", “$username”, “$password”)or die(“cannot connect”);
mysql_select_db("$db_name")or die(“cannot select DB”);

// username and password sent from form

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql=“SELECT * FROM $tbl_name WHERE name=’$myusername’ and password=’$mypassword’”;

// Mysql_num_row is counting table row

// If result matched $myusername and $mypassword, table row must be 1 row

// Register $myusername, $mypassword and redirect to file “login_success.php”
else {
$msg = “Wrong Username or Password”;
?> [/php]

There are other pages but the error keeps coming to this one.

However whenever i fill in to see what happens it takes me to the successful login page but gives me this error:

Notice: Use of undefined constant myusername - assumed ‘myusername’ in C:\wamp\www\PartyTime\login_success.php on line 3

Deprecated: Function session_is_registered() is deprecated in C:\wamp\www\PartyTime\login_success.php on line 3

The code:


Login Successful [/php]

Some help would be appreciated! Thanks guys!


The first one is easy - the script does not know the credentials for the database connection. You might want to set $username and $password before using them.

The second one is also easy - and by the way, it is not an error, merely a notice. Change this:

To this:

In PHP, a string is always either in single quotes, double quotes or HEREDOC syntax. If you omit all three of them, you tell PHP to consider that word as a constant. PHP tries to find the constant, does not find it, tries the string instead and lets you know that it did this by outputting a notice!

Sponsor our Newsletter | Privacy Policy | Terms of Service