kevinwcaulfield Posted October 28, 2009 Share Posted October 28, 2009 Hello, I have created a simple login system. I have created a table, as follows: CREATE TABLE `members` ( `id` int(4) NOT NULL auto_increment, `username` varchar(65) NOT NULL default '', `password` varchar(65) NOT NULL default '', PRIMARY KEY (`id`) ) TYPE=MyISAM AUTO_INCREMENT=2 ; -- -- Dumping data for table `members` -- INSERT INTO `members` VALUES (1, 'john', '1234'); How can I create a register page for people to join? Can somebody help me? lets say that $mysql_host = "qwerty"; $mysql_database = "database"; $mysql_user = "user1"; $mysql_password = "password"; All help appreciated. (any form of captcha possible?) Quote Link to comment https://forums.phpfreaks.com/topic/179393-adding-register-page-to-login/ Share on other sites More sharing options...
mikesta707 Posted October 28, 2009 Share Posted October 28, 2009 well you have the insert command. What you need to do is use an HTML form to send data to a page. then using the $_POST or $_GET array (depending on if your method was post or get) you can then take that data, and insert it into the database via the insert command you have (changed to have the data from the post/get array instead of hard coded values of course) for captcha you can go here Quote Link to comment https://forums.phpfreaks.com/topic/179393-adding-register-page-to-login/#findComment-946573 Share on other sites More sharing options...
kevinwcaulfield Posted October 28, 2009 Author Share Posted October 28, 2009 Yes Thank you, but I am aware, but for the php I am not the best. Could you provide an example or some code that I could use? Quote Link to comment https://forums.phpfreaks.com/topic/179393-adding-register-page-to-login/#findComment-946575 Share on other sites More sharing options...
jonsjava Posted October 28, 2009 Share Posted October 28, 2009 Sure. Here's some examples. <?php top("Enter Appropriate Data"); if($_GET['error'] == "missing"){ echo "<div align='center'><h4 style='color:red'>Enter all data</h4><br></div>"; } elseif($_GET['error'] == "match"){ echo "<div align='center'><h4 style='color:red'>Passwords must match</h4><br></div>"; } elseif($_GET['error'] == "email"){ echo "<div align='center'><h4 style='color:red'>Email must be valid</h4><br></div>"; } elseif($_GET['error'] == "weak"){ echo "<div align='center'><h4 style='color:red'>Weak Password, must be 6+ characters, and not a common word</h4><br></div>"; } elseif($_GET['error'] == "exists"){ echo "<div align='center'><h4 style='color:red'>Weak Password, must be 6+ characters</h4><br></div>"; } elseif($_GET['error'] == "orig"){ echo "<div align='center'><h4 style='color:red'>Select a UNIQUE email and/or password</h4><br></div>"; } elseif($_GET['error'] == "phone"){ echo "<div align='center'><h4 style='color:red'>Phone number must be less than 10 characters</h4><br></div>"; } ?> <div align="center"> <form name=form method="post" action="p_register.php"> <table> <tr> <td>Email</td> <td><input name="username" type="text"></input></td> </tr> <tr> <td>Password</td><td> <input name="passwd" type="password"></input></td> </tr> <tr> <td>Re-enter Password</td> <td><input name="passwd2" type="password"></input></td> </tr> <tr> <td>Real Name or Company Name</td> <td><input name="rName" type="text"></input></td> </tr> <tr> <td>Phone - Optional</td> <td><input name="phone" type="text"></input></td> </tr> <tr> <td><input name="eType" value="1" type="radio">Employer</input></td> <td><input name="eType" value="0" type="radio" checked>Prospective Employee</input></td> </tr> <tr> <td><input type="submit" value="submit"></input></td> </tr> </table> </form> </div> <?php bottom(); ?> p_register.php include('./db_config.php'); session_start(); $link = mysql_connect($db_host, $db_user, $db_password) or die ("Connection failed due to: " . mysql_error()); mysql_select_db ($db_name) or die("Selection failed due to: " . mysql_error()); $query = "SELECT * FROM account WHERE password='" . $_POST['passwd'] . "'"; $result = mysql_query($query) or die("Query failed due to: " . mysql_error()); $passtest = mysql_num_rows($result); $query = "SELECT * FROM account WHERE user_id='" . $_POST['username'] . "'"; $result = mysql_query($query) or die("Query failed due to: " . mysql_error()); $idtest = mysql_num_rows($result); if (!(empty($_POST['phone']))){ $phone = preg_replace('/\s/', '', $_POST['phone']); $phone = str_replace('-', '', $phone); settype($phone, "int"); } if ((empty($_POST['username'])) || (empty($_POST['passwd'])) || (empty($_POST['passwd2'])) || (empty($_POST['rName']))){ header("Location: ./register.php?error=missing"); exit; } elseif (!(eregi('^[a-z0-9._%+-]+@[a-z0-9._%-+]+\.[a-z0-9]{2,6}$', $_POST['username']))) { header("Location: ./register.php?error=email"); exit; } elseif (($_POST['passwd']) != ($_POST['passwd2'])){ header("Location: ./register.php?error=match"); exit; } elseif (strlen($_POST['passwd']) <= 6) { header("Location: ./register.php?error=weak"); exit; } elseif (strlen($phone) > 10) { header("Location: ./register.php?error=phone"); exit; } elseif (($idtest != 0)) { header("Location: ./register.php?error=orig"); exit; } else{ require('./resource.php'); top('Register Successful'); $usrid = $_POST['username']; $passwd = $_POST['passwd']; $name = $_POST['rName']; $emp = $_POST['eType']; settype($emp, "int"); $query = "INSERT INTO account (user_id, name, password, employer, phone) VALUES('$usrid','$name','$passwd','$emp','$phone')"; mysql_query($query) or die("Query failed due to: " . mysql_error()); //initial UID grab in p_login.php or whatever file name you're using $vUserID=trim($_POST["username"]); //after validating email using regular expressions AND //inserting into account table, send email to user to further validate //the function "mysql_insert_id()" gets the ID generated from the previous INSERT operation $to = "$vUserID"; $subject = 'VALIDATE EMAIL (USER ID)'; $message = "Please copy and paste the Web address below into your Web browser's address bar...\n This allows YOUR_SITE to validate your email\n Thank you!!!\n \n YOUR_SITE/validate.php?eml=1&pk=" . mysql_insert_id(); $headers = 'From: YOUR@EMAIL'; mail($to, $subject, $message, $headers); echo "<div align='center'><h4 style='color:red'>You must now click on the link sent to your email to validate</h4></div>"; echo "<div align='center'><a href='./login.php'>Click to return to login</a></div>"; bottom(); } You'll need to do some serious code cleanup, and work in some checks before using this, but you get what you ask for. If you had posted some code, I'm sure people would have been more receptive to helping more. Just a reminder: the code posted here sucks. It's some code I wrote back when I was learning PHP. It should only be used as a guideline to how registration forms work. Quote Link to comment https://forums.phpfreaks.com/topic/179393-adding-register-page-to-login/#findComment-946582 Share on other sites More sharing options...
kevinwcaulfield Posted October 28, 2009 Author Share Posted October 28, 2009 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/179393-adding-register-page-to-login/#findComment-946587 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.