Ok I want to make a user and password login that goes into the mysql database then when the users log in it querys the database and validates the username and password. Everything goes well until I get to the validation. Heres what I've got so far
I make the database to hold the username and password like this:
mysql>create database users;
Query OK, 1 row affected (0.58 sec)
mysql> use user;
Database changed
mysql> create table users
-> (
-> username varchar(15) null,
-> password varchar(15) null
-> )
-> ;
Query OK, 0 rows affected (0.28 sec)
mysql>
Ok so that's how I created my database then I move onto creating the index.html page
<head>
<h2>
User Login
</h2>
<form method=post action="/login.php">
</head>
<body>
<b>
<br>
Username
<br>
</b>
<input type=text size=15 name="username">
<br>
<b>
UserPassword
</b>
<br>
<input type=password size=15 name="password">
<br>
<input type=submit name=submit value="Login">
<input type=reset name=reset value="Clear">
<br>
<a href="/register.html">Register</a>
</form>
</body>
That made a nice little login form for me, but since there is nothing in the database yet to log in and validate the username and password you have to click the link that says Register. Now Here is what my register.html file looks like.
<head>
<h2>
User Registration
</h2>
<form method=post action="create_entry.php">
</head>
<body>
<b>
<br>
Username
<br>
</b>
<input type=text size=15 name=username>
<br>
<b>
UserPassword
</b>
<br>
<input type=password size=15 name=password>
<br>
<input type=submit name=submit value="Register">
<input type=reset name=reset value="Clear">
</form>
</body>
Once the user files out the form and hit's submit I make a .php file to enter the text into the database I call it <form method=post action="create_entry.php"> so this is what my creat_entry.php file looks like
<?php
mysql_connect("localhost", "root") or
die ("Could not connect to database");
mysql_select_db("users") or
dir ("Could not select database");
if ($submit == "Register")
{
$query = "insert into user
(name, password) values ('$name', '$password')";
mysql_query($query) or
die (mysql_error());
?>
<h3>You are now registered</h3>
<a href="index.html">Go back to main page</a>
<?php
}
else
{
include("notvalid.html");
}
?>
This will put the user input into the database, and it works if the username is already taken the user gets to go the notvalid.html . So after the user registers a username and password we go back to the index.html that has the login.
<head>
<h2>
User Login
</h2>
<form method=post action="/login.php">
</head>
<body>
<b>
<br>
Username
<br>
</b>
<input type=text size=15 name="username">
<br>
<b>
UserPassword
</b>
<br>
<input type=password size=15 name="password">
<br>
<input type=submit name=submit value="Login">
<input type=reset name=reset value="Clear">
<br>
<a href="/register.html">Register</a>
</form>
</body>
This time I hit submit after entering a username and password. When the user hits submit it's going to a php file called /login.php . This is the php file that will validate the username and password. But I can't seem to get it to work at all. And this is where I'm asking for help. Here is what my login.php file looks like I need help with this
<?
if ($submit = "Login")
{
mysql_connect("localhost","root")
or die ("cant connect");
mysql_select_db("user")
or die ("cant change");
$result=mysql_query("select * from user where name='$username'")
or die ("cant do it");
while ($row=mysql_fetch_array($result)) {
if ($row["password"]==$password )
{
printf("Successfully Logged In!");
}else{
print("Nope");
}
}
}
?>