| | |
Name and Password login
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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.
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.
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!
PHP Syntax (Toggle Plain Text)
<?php session_start(); if (isset($_POST['submit'])) { // Connect to the database or die. $connection = mysql_connect("DB-ADDRESS", "USERNAME", "PASSWORD"); if (!$connection) { die("The Database connection failed. " . "<br />" . mysql_error()); } // Select the table within the database or die. $database_select = mysql_select_db("TABLENAME", $connection); if (!$database_select) { die("The Database selection failed. " . "<br />" . mysql_error()); } // Get the POST variables. $myusername = $_POST['myusername']; $mypassword = $_POST['mypassword']; // To protect MySQL injection, we stripslashes and use mysql_real_escape_string. $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); // Run a query to bring back the users' record from the database. $result = mysql_query("SELECT * FROM TABLENAME WHERE username = '$myusername' AND password = '$mypassword' LIMIT 1", $connection); // If the query is not set meaning it failed, then die. if (!$result) { die("The Database query failed. " . "<br />" . mysql_error()); } // If it successfully returned one row... if (mysql_num_rows($result) == 1) { // Bind the returned results to an array. $row = mysql_fetch_array($result); // Register $_SESSION variables and redirect to "success.php". $_SESSION["myusername"] = $myusername; $_SESSION["firstname"] = $firstname; // Redirect the person to the new page. header("location:success.php"); } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP: Login</title> </head> <body> <form name="loginForm" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <label for="myusername">Username</label> <br /> <input name="myusername" id="myusername" type="text" /> <br /> <br /> <label for="mypassword">Password</label> <br /> <input name="mypassword" id="mypassword" type="text" /> <br /> <br /> <input name="submit" id="submit" type="submit" value="Login" /> </form> </body> </html>
"Beneath this mask there is more than flesh. Beneath this mask there is an idea, Mr. Creedy, and ideas are bulletproof." - V
•
•
Join Date: Jun 2008
Posts: 62
Reputation:
Solved Threads: 3
There is a tutorial that I would recommend. It can be found at
http://www.jdtmmsm.com/tutorials/bas...entication.php
Hoe This Helps
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.
![]() |
Similar Threads
- Updated : Simple ASP.Net Login Page (ASP.NET)
- HELP!! Monitor Shows NO SIGNAL after windows loading / before login page (Windows NT / 2000 / XP)
- code for login and password..using vb6 (Visual Basic 4 / 5 / 6)
- Login Problems with Hotmail (Web Browsers)
- help newbie alert needs help with login page (ASP.NET)
- Deleting Saved Password in XP (Windows NT / 2000 / XP)
- Password Problem (Windows NT / 2000 / XP)
- IE remember password causes login errors (Web Browsers)
- Cannot Login to Mac (OS X)
Other Threads in the PHP Forum
- Previous Thread: Can anybody help me in writing this very simple script
- Next Thread: mail() custom format?
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





