Jump to content
xisto Community
Sign in to follow this  
Daniel666

Login System Using A Mysql Db How do i do this?

Recommended Posts

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

<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:

<?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 :blink:

Share this post


Link to post
Share on other sites

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.

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

<?phpsession_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 :blink:

Share this post


Link to post
Share on other sites

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 :blink:)

Share this post


Link to post
Share on other sites
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 :( no need for coding but coding skills does come in handy

Share this post


Link to post
Share on other sites

This is the login main page for the one i use.

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>

Share this post


Link to post
Share on other sites

none of this helps ill paste it here This is the login main page for the one i use.CODEif($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> ahaslam Posted May 14 2008, 05:14 PM 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 no need for coding but coding skills does come in handy Daniel666 Posted Aug 23 2007, 09:02 AM 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 ) kelvinmaki Posted Aug 22 2007, 12:17 PM 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<?phpsession_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 Daniel666 Posted Aug 22 2007, 11:57 AM 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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.