So I’m learning how to make a simple login system for a website I’m making and I’m getting this error.
Notice: Use of undefined constant myusername – assumed ‘myusername’ in /home/dkitterm/public_html/index.php on line 4
These are lines 3-6.
session_start();
if(!session_is_registered(myusername)){
header("location: main_login.php");
}
This is my check login page as well.
<?php
$host="localhost";
$username="dkitterm";
$password="";
$db_name="";
$tbl_name="members";
//connect to server and db
mysql_connect("$host", "$username", "$password") or die("Server Down");
mysql_select_db("$db_name") or die("cannot select DB");
//username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
//debunk
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
//encrypt password
$encrypted_mypassword=md5($mypassword);
$sql="SELECT * FROM members WHERE login='$myusername' and password='$encrypted_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: index.php");
}
else {
echo "Wrong Username or Password";
}
?>
First of all your check page doesn’t protect you 100% so you need
to
and put quotations around myusername otherwise it will treat it as a constant which its not