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:
[php]<?php
session_start();
$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
$myusername=$_POST[“username”];
$mypassword=$_POST[“password”];
// 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’”;
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file “login_success.php”
session_register(“myusername”);
session_register(“mypassword”);
header(“location: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:
[php]<?php
session_start();
if(!session_is_registered(myusername)){
header(“location:main_login.php”);
}
?>
Some help would be appreciated! Thanks guys!
Ashwin