Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Login System Using A Mysql Db, How do i do this?
Daniel666
post Aug 22 2007, 11:57 AM
Post #1


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 7
Joined: 22-August 07
Member No.: 24,272



Hi guys, ive got a registration system that looks something like the one below:

CODE
<html>
<body><form action="insert.php" method="post">
Firstname: <input type="text" name="username" />
Lastname: <input type="text" name="password" />
<input type="submit" />
</form></body>
</html>


Then i have inset.php, which looks like the following:

CODE
<?php
$con = mysql_connect("localhost","autobot","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}mysql_select_db("my_db", $con);$sql="INSERT INTO person (username, password)
VALUES
('$_POST[username]','$_POST[password]')";if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";mysql_close($con)
?>



Now my question is, how do i create a login system using PHP and MYSQL, because im missing something obvios here i think.

~Thank you smile.gif
Go to the top of the page
 
+Quote Post
kelvinmaki
post Aug 22 2007, 12:17 PM
Post #2


Advanced Member
Group Icon

Group: Members
Posts: 170
Joined: 30-July 07
Member No.: 23,704



Actually looking at your Form, its quite weird. Having Firstname as username and Lastname as password. But anyway, just take assume that you want it to be like this. So the question is you want to allow the user to login after registration?? Below will be an example of a login script.

Here is a minor modification to your registration form. This will be something like login.php for the user to enter their data.

CODE
<html>
<body><form action="access.php" method="post">
Username: <input type="text" name="username" />
Password: <input type="text" name="password" />
<input type="submit" />
</form></body>
</html>


So after Submit button is click, it will be send to access.php. The codes below will be used to verify the user.

CODE
<?php
session_start();

$con = mysql_connect("localhost","autobot","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$sql="SELECT * FROM person where username = '$_POST[username]' and password = '$_POST[password]'";
$result = mysql_query($sql);
if ($result == 0)
{
die('Error: ' . mysql_error());
}

echo "Login Success";
$_SESSION[‘user’] = $result;
mysql_close($con)
?>



The above is just an example of login. You can use that session on every page by calling $_SESSION[‘user’]. There's a lot better ones out there and of course you can use those for free. If you want more security, you can use hashing or security id for accessing pages. Hope this help a bit. Cheers wink.gif
Go to the top of the page
 
+Quote Post
Daniel666
post Aug 23 2007, 09:02 AM
Post #3


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 7
Joined: 22-August 07
Member No.: 24,272



Alright, i got a login and registration system working, the last thing i need is how to show differant users differant things, lets say i want the admin to see "Welcome Admin" and i want a member to see "Login successful" how would i do that?

(sorry if im annoying you guys now tongue.gif)
Go to the top of the page
 
+Quote Post
ahaslam
post May 14 2008, 05:14 PM
Post #4


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 24
Joined: 14-May 08
From: uk gb
Member No.: 30,333



login code ect.this is a really good code worked great for me. it has reg page, login page ect. really good just put where your ftp is and open index.html and follow on from there tongue.gif no need for coding but coding skills does come in handy
Go to the top of the page
 
+Quote Post
darkken
post Jul 2 2008, 09:34 PM
Post #5


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 10
Joined: 2-July 08
Member No.: 31,263



This is the login main page for the one i use.
CODE
if($session->logged_in){
   echo "<h1>Logged In</h1>";
   echo "Welcome <b>$session->username</b>, you are logged in. <br><br>"
       ."[<a href=\"userinfo.php?user=$session->username\">My Account</a>]   "
       ."[<a href=\"useredit.php\">Edit Account</a>]   "
       ."[<a href=\"../upload/upload.php\">File Upload</a>]   "
       ."[<a href=\"../egbtdata.php?start=0&end=50&order=playerID\">EGBT Database</a>]  ";
   if($session->isAdmin()){
      echo "[<a href=\"admin/admin.php\">Admin Center</a>]   ";
   }
   echo "[<a href=\"process.php\">Logout</a>]";
}
else{
?>

<h1>Login</h1>
<?
/**
* User not logged in, display the login form.
* If user has already tried to login, but errors were
* found, display the total number of errors.
* If errors occurred, they will be displayed.
*/
if($form->num_errors > 0){
   echo "<font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font>";
}
?>
<form action="/includes/process.php" method="POST">
<table align="left" border="0" cellspacing="0" cellpadding="3">
<tr><td>Username:</td><td><input type="text" name="user" maxlength="30" value="<? echo $form->value("user"); ?>"></td><td><? echo $form->error("user"); ?></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass" maxlength="30" value="<? echo $form->value("pass"); ?>"></td><td><? echo $form->error("pass"); ?></td></tr>
<tr><td colspan="2" align="left"><input type="checkbox" name="remember" <? if($form->value("remember") != ""){ echo "checked"; } ?>>
<font size="2">Remember me next time     
<input type="hidden" name="sublogin" value="1">
<input type="submit" value="Login"></td></tr>
<tr><td colspan="2" align="left"><br><font size="2">[<a href="forgotpass.php">Forgot Password?</a>]</font></td><td align="right"></td></tr>
<tr><td colspan="2" align="left"><!--<br>Not registered? <a href="register.php">Sign-Up!</a>--></td></tr>
</table>
</form>


Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. How Do I Make A RPG Battle System?(13)
  2. Recover Tables From A MySQL .frm File(6)
  3. Can't Login.(3)
  4. How To Connect MySQL With Flash?(8)
  5. Www.modthesims2.com - Sims 2 Mods Site(5)
  6. [PHP + MySQL] Encrypting Data(5)
  7. CuteNews: PHP-based Blog System - No MySQL(10)
  8. What Is Unicode System(1)
  9. MySQL, Multiple Tables(22)
  10. Preferred Forum System(22)
  11. Mysql And Php(15)
  12. Which Operating System Is Better?(41)
  13. Cracking Wireless Access Point Password?(20)
  14. Js/php/mysql Timer(2)
  15. Access(17)
  1. Very Simple Login-script(18)
  2. How To Make A Private Message System.(7)
  3. Mysql - So Hard(14)
  4. Free Login Script(1)
  5. Php Login Script(0)
  6. Sun Bought Mysql(6)
  7. How To: Make A Simple Php Forum System(4)
  8. Before Unplugging A Usb Disk From An Opensuze System(9)
  9. Mysql Backup With Another Address?(4)
  10. What Is My Mysql Url (connecting Through Java/jdbc)(4)
  11. I Have An Error With My Mysql Connection(6)
  12. Mysql Persistant Connections?(2)
  13. Mysql Storage Engine Error 28(5)


 



- Lo-Fi Version Time is now: 4th July 2008 - 04:22 PM