Name and Password login

Reply

Join Date: Apr 2007
Posts: 15
Reputation: stealthmode is an unknown quantity at this point 
Solved Threads: 0
stealthmode's Avatar
stealthmode stealthmode is offline Offline
Newbie Poster

Name and Password login

 
0
  #1
Nov 25th, 2008
I have been trying to find a simple name and password tutorial that works and is easy to follow. Not having much luck.
The name and password will be in a text file or mysql database which the user will be given, i do not need forgot password or email address etc. ( I can add later if need be)
I want members to log-in which will then give them a form to fill in and send. (About 5 members so not a lot)
PHP5 and MySql 5 and apache installed and hopefully working correctly this end.
I have managed to make a form and use php to extract and send the form data to an e-mail address with a thank-you going to the actual persons e-mail address on the form they filled in so I am hoping this will be quite easy to do.
Take it slowly with me as still green at coding all this.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 110
Reputation: antwan1986 is an unknown quantity at this point 
Solved Threads: 8
antwan1986's Avatar
antwan1986 antwan1986 is offline Offline
Junior Poster

Re: Name and Password login

 
0
  #2
Nov 25th, 2008
Hopefully this should get you started. I've commented the code to make understanding easier, let me know if you've any questions; I'm here to help!

  1. <?php
  2. session_start();
  3.  
  4. if (isset($_POST['submit'])) {
  5. // Connect to the database or die.
  6. $connection = mysql_connect("DB-ADDRESS", "USERNAME", "PASSWORD");
  7. if (!$connection) { die("The Database connection failed. " . "<br />" . mysql_error()); }
  8.  
  9. // Select the table within the database or die.
  10. $database_select = mysql_select_db("TABLENAME", $connection);
  11. if (!$database_select) { die("The Database selection failed. " . "<br />" . mysql_error()); }
  12.  
  13. // Get the POST variables.
  14. $myusername = $_POST['myusername'];
  15. $mypassword = $_POST['mypassword'];
  16.  
  17. // To protect MySQL injection, we stripslashes and use mysql_real_escape_string.
  18. $myusername = stripslashes($myusername);
  19. $mypassword = stripslashes($mypassword);
  20. $myusername = mysql_real_escape_string($myusername);
  21. $mypassword = mysql_real_escape_string($mypassword);
  22.  
  23. // Run a query to bring back the users' record from the database.
  24. $result = mysql_query("SELECT * FROM TABLENAME WHERE username = '$myusername' AND password = '$mypassword' LIMIT 1", $connection);
  25.  
  26. // If the query is not set meaning it failed, then die.
  27. if (!$result) { die("The Database query failed. " . "<br />" . mysql_error()); }
  28.  
  29. // If it successfully returned one row...
  30. if (mysql_num_rows($result) == 1) {
  31. // Bind the returned results to an array.
  32. $row = mysql_fetch_array($result);
  33.  
  34. // Register $_SESSION variables and redirect to "success.php".
  35. $_SESSION["myusername"] = $myusername;
  36. $_SESSION["firstname"] = $firstname;
  37.  
  38. // Redirect the person to the new page.
  39. header("location:success.php");
  40. }
  41. }
  42. ?>
  43. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  44. <html xmlns="http://www.w3.org/1999/xhtml">
  45. <head>
  46. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  47. <title>PHP: Login</title>
  48. </head>
  49.  
  50. <body>
  51. <form name="loginForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
  52. <label for="myusername">Username</label> <br />
  53. <input name="myusername" id="myusername" type="text" /> <br /> <br />
  54. <label for="mypassword">Password</label> <br />
  55. <input name="mypassword" id="mypassword" type="text" /> <br /> <br />
  56. <input name="submit" id="submit" type="submit" value="Login" />
  57. </form>
  58. </body>
  59. </html>
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 62
Reputation: PomonaGrange is an unknown quantity at this point 
Solved Threads: 3
PomonaGrange PomonaGrange is offline Offline
Junior Poster in Training

Re: Name and Password login

 
0
  #3
Nov 25th, 2008
There is a tutorial that I would recommend. It can be found at
http://www.jdtmmsm.com/tutorials/bas...entication.php

Hoe This Helps
There are alot of people smarter than me, BUT at least I try to be of some help. Of coarse I'm not perfect, I need help too.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC