Well I'm completely new to the whole php and mysql aspect of web development and this is my first project. I've got a script from a tutorial that I'm using as a shell for a login system I plan on expounding on after I can get this to work. Currently I've got 3 files:
main_login.php
checklogin.php
login_success.php
I set up a table called "members" which stores the ID#, Username, and Password and then set up the files on the site. The main_login.php presents a form to enter the username and password in. Then redirects to checklogin.php to verify the information with the table in the database and is supposed to jump to login_success.php if it checks out or return "invalid username or password" if the info isn't in the table. I put one value (username = john, password = 1234) into the table and when I use it to log in it takes me to login_success.php as if it's cleared but then gives me the error:
Notice: Use of undefined constant myusername - assumed 'myusername' in /s/bach/k/under/prew/public_html/login_success.php on line 2
Login Successful
I'm not exactly sure why it's displaying this. I went back to checklogin.php and it's showing the same error for both myusername and mypassword. Anyone know what might be causing this? Is it a php problem or something wrong with my table?
Thanks,
Nate
To see if it will help at all, here's the code as it stands on the site.
main_login.php
<form name="form1" method="post" action="checklogin.php">
Username: <input style="margin-right: 5px;" type="text" size="10" maxlength="40" name="myusername" id="myusername" />
Password: <input style="margin-right: 5px;" type="password" size="10" maxlength="10" name="mypassword" id="mypassword" />
<input style="background-color:#222222; border: 1px solid #000000; color: #EFECCA; outline: none;" type="submit" name="Submit" value="Login" />
</form>
checklogin.php
<?php
ob_start();
$host="localhost"; // Host name
$username="prew"; // Mysql username
$password="xxxxxx"; // Mysql password
$db_name="prew"; // Database name
$tbl_name="members"; // 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");
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
if($result){
echo "go";
}
//mysql_num_row is counting table row
$count=mysql_num_rows($result);
//if result match $myusername and mypassword table row must be 1 row
if($count==1){
session_register("myusername");
header("location:login_success.php");
}
else {
echo "Wrong Username or Password";
}
ob_end_flush();
?>
login_success.php
<?php session_start();
if(!session_is_registered(myusername)){
header("location:main_login.php");
} ?>
<html>
<body>
Login Successful
</body>
</html>