Jump to content

Creating Login/Redgister System From Scratch


dv90

Recommended Posts

Im pretty inexperienced with php and mysql but I managed to make a register script. It uses post method to insert 2 fields in, Username and Password.

 

Register Script:

<?php
$con = mysql_connect("localhost","***","******");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("login", $con);
$sql="INSERT INTO users (Username, Password)
VALUES
('$_POST[user]','$_POST[pass]')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
mysql_close($con)
?>
<html>
<head>
<script type="text/javascript">
<!--
function delayer(){
    window.location = "index.html"
}
//-->
</script>
</head>
<body onLoad="setTimeout('delayer()', 1500)" bgcolor=#333333>
<center>
<font color=#fff>Registration Successful!</font>
</center>
</body>
</html>

 

But now I need a Login script. I got this far, but i dont think im even close. I need to use $_POST[user] and $_POST[pass] and check if the info is right. Im stuck. Please help.

 

Extra codes:

 

Index with register and login:

<html>
<body>
<b>LOGIN</b>
<form action="login.php" method="post">
User:<input type="text" name="user" />
Pass:<input type="text" name="pass" />
<input type="submit" />
</form>
<b>REGISTER</b>
<form action="reg.php" method="post">
User:<input type="text" name="user" />
Pass:<input type="text" name="pass" />
<input type="submit" />
</form>
</body>
</html>

 

Login code so far:

<?php
$con = mysql_connect("localhost","******","********");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("login", $con);

$result = mysql_query("SELECT Username FROM users");

echo "<table border='1'>
<tr>
<th>Username</th>
<th>Password</th>
</tr>";
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['Username'] . "</td>";
  echo "<td>" . $row['Password'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
mysql_close($con);
?>

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.