I have a question.. My code that I have doesnt really work so.. anyways.. I have MYSQL, PHP, and a APACHE Server. I have a login box for people to login. Whats the script to make it check if your username is stored in MySQL.. if you want to see me code it's this..
<?
session_start();
session_register("log");
$log = "";
?>
<html>
<head>
<title></title>
</head>
<body>
<?
$conn = mysql_connect("localhost", "xxxxxxxx", "xxxxxxxxxxx") or die ("Could not connect to database!");
$db = mysql_select_db("xxxxxxxxxxxxx") or die ("Could not select database");
if (isset($signin)){
$log = $username;
$query = "select * from table where username='$username' and password=(password('$password'))";
$result = mysql_query($query) or die (mysql_error());
$isAuth = false;
while($row = mysql_fetch_array($result))
{
if($row['username'] == $username)
{
$isAuth = true;
}
}
if($isAuth)
{
?>
<br><br>
You are logged In!!
<?
}
else
{
?> <br>
<h2><font color="red">Invalid username or password</font></h2>
<form name="login" action="login.php" method="post"><br>
Username: <input name="username" type="text"><BR>
Password: <input name="password" type="password"><BR>
<input type="submit" name="signin" value="Sign In">
<?
}
}
else
{
?>
<form name="login" action="login.php" method="post"><br>
<b>Login Area for Intranet</b><br><br>
Username: <input name="username" type="text"><BR>
Password: <input name="password" type="password"><BR>
<input type="submit" name="signin" value="Sign In"><br>
<?
}
?>
</form>
</body>
</html>
Whenever I uses this it doesn't validate it or anything.
Also.. for my code to register..
<html>
<head>
<title></title>
<body>
<?
$conn = mysql_connect("localhost", "xxxxxxxxx", "xxxxxxxxxxxx") or die ("Could not connect to database!");
$db = mysql_select_db("xxxxxxxxxxxxxxx") or die ("Could not select database");
if (isset ($create))
{
$queryc = "select * from table where username = '$username';";
$resultc = mysql_query($queryc) or die ("Can not select user database");
$alfonse = false;
while ($rowc = mysql_fetch_array($resultc))
{
if ($uname == $rowc['uname'])
{
$alfonse = true;
}
else
{
}
}
if ($alfonse)
{
echo "<h3>Username already in use.<br>Please select another name.</h3>";
?>
<form name="create" method="POST" action="create.php">
Username <input type="text" name="username"><br>
Password <input type="password" name="password"><br>
<input type="submit" name="create" value="Create Account">
</form>
<?
}
else
{
$query = "insert into table (username, password) values ('$username', password('$password'));";
$result = mysql_query($query) or die ("Could not add to user");
}
}
else
{
?>
<form name="create" method="POST" action="create.php">
Username <input type="text" name="username"><br>
Password <input type="password" name="password"><br>
<input type="submit" name="create" value="Create Account">
</form>
<?
}
?>
</body>
</html>
When I uses this code.. I type in the the username and password.. and then it doesn't add it to MySQL.. it just goes to the next page... create.php.. why???
My Site