save as accountsys.php
has comments on lines u need to edit
Code: Select all
<HTML>
<HEAD>
<TITLE>Login form ;D</TITLE>
<?PHP
$user_name = "root"; //user name for the SQL DB
$password = ""; //password for the SQL DB
$database = "USERS"; //SQL DB
$server = "127.0.0.1"; //IP of the SQL server
if(isset($_POST['Submit1']) && isset($_POST['username']) && isset($_POST['password']))
{
$uname = $_POST['username'];
$pword = $_POST['password'];
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found)
{
$SQL = "SELECT * FROM tb_USERS WHERE NAME = '$uname'"; //tb_USERS is the table name!
$result = mysql_query($SQL);
if($db_field = mysql_fetch_assoc($result))
{
if($db_field['PASSWORD'] == $pword)
{
print "Welcome back ".$uname."!";
}
else
{
print "Wrong login info FAGFACE!";
}
}
else
{
print "Name ".$uname." not found!";
}
}
mysql_close($db_handle);
}
else if(isset($_POST['Register1']) && isset($_POST['username']) && isset($_POST['password']))
{
$uname = $_POST['username'];
$pword = $_POST['password'];
$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found)
{
$SQL = "SELECT * FROM tb_USERS WHERE NAME = '$uname'"; //tb_USERS is the table name!
$result = mysql_query($SQL);
if($db_field = mysql_fetch_assoc($result))
{
print "The name ".$uname." is already registered!";
}
else
{
$SQL = "INSERT INTO tb_USERS (NAME, PASSWORD) VALUES ('$uname', '$pword')"; //tb_USERS is the table name!
$result = mysql_query($SQL);
if($result)
{
print "User ".$uname." was added to the database!";
}
}
}
mysql_close($db_handle);
}
else
{
$uname="username";
}
?>
</HEAD>
<BODY>
<FORM NAME ="form1" METHOD ="POST" ACTION = "accountsys.php">
Username:<br><INPUT TYPE = "TEXT" VALUE ="<?php print $uname; ?>" Name = "username"><br>
Password:<br><INPUT TYPE = "TEXT" VALUE ="" Name = "password"><br>
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Login">
<INPUT TYPE = "Submit" Name = "Register1" VALUE = "Register">
</FORM>
</BODY>
</HTML>