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);
?>

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.