RitchieGunz Posted April 30, 2007 Author Share Posted April 30, 2007 Nope, Im just using wordpad. So all that goes into signup.php? Then whats supposed to go into check.php? Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-241936 Share on other sites More sharing options...
bobleny Posted April 30, 2007 Share Posted April 30, 2007 Well, in all reality you could put it all in one page if you wanted... I have my entire site and a forum on one page... You should get an editor that offers syntax highlighting. I use geany and phpdesigner... You need the form in signup.php so as to sign your users up. You then need to place the rest in check.php Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-241943 Share on other sites More sharing options...
RitchieGunz Posted April 30, 2007 Author Share Posted April 30, 2007 Im pretty sure I slaughtered this, sorry for being a bother, lol This is what I got in signup.php ... When I add that stuff from Reply #23, It shows up when I view signup.php so I put it in check.php This is signup.php: <html> <head> <title>Sign Up</title> </head> <body> <form action="check.php" method="post"> Username: <input type="text" name="username" /><br /> Password: <input type="password" name="password" /><br /> Verify Password: <input type="password" name="varpassword" /><br /> E-mail: <input type="text" name="email" /><br /> <input type="submit" value="Sign Up" /> </form> </body> </html> And this is in check.php .. I did what you told me to in the comments, but I probably messed that up. <?php echo "<form action=/"check.php/" method=/"post/">" if ($_SESSION['short_username'] == TRUE) { echo "Your username was too short!<br />"; $_SESSION['short_username'] = FALSE; } if ($_SESSION['bad_username'] == TRUE) { echo "Usernames may only contain alphanumeric characters, dashes (-) and underscores (_)<br />"; $_SESSION['bad_username'] = FALSE; } echo "Username: <input type=/"text/" name=/"username/" /><br />" if ($_SESSION['short_password'] == TRUE) { echo "Your password was too short!<br />"; $_SESSION['short_password'] = FALSE; } if ($_SESSION['bad_password'] == TRUE) { echo "Passwords may only contain alphanumeric characters<br />"; $_SESSION['bad_password'] = FALSE; } echo "Password: <input type=/"password/" name=/"password/" /><br /> if ($_SESSION['match_password'] == TRUE) { echo "Your passwords did not match!<br />"; $_SESSION['match_password'] = FALSE; } echo "Verify Password: <input type=/"password/" name=/"varpassword/" /><br />" if ($_SESSION['bad_email'] == TRUE) { echo "You have entered an invalid E-mail address<br />"; $_SESSION['bad_email'] = FALSE; } echo "E-mail: <input type=/"text/" name=/"email/" /><br />" <input type=/"submit/" value=/"Sign Up/" /> </form> if (strlen($_POST['username']) < 4) { if (strlen($_POST['password']) < 6) { if (strlen($_POST['email']) < { //There username contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['short_username'] = TRUE; $_SESSION['short_password'] = TRUE; $_SESSION['bad_email'] = TRUE; $_SESSION['match_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; { //Do that for all the fields. //You should change the "4" to an "8" for the email address. //No email address will have less than 8 characters! if (preg_match("/[^a-zA-Z0-9_-]/", $_POST['username'])) { if (preg_match("/[^a-zA-Z0-9]/", $_POST['password'])) { if (preg_match("/[^a-zA-Z0-9_-.@]/", $_POST['email'])) { //There username contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_username'] = TRUE; $_SESSION['bad_password'] = TRUE; $_SESSION['match_password'] = TRUE; $_SESSION['bad_email'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //Again, do that for all the fields. //You should use preg_match("/[^a-zA-Z0-9]/", $_POST['password']) for the password. //You should use preg_match("/[^a-zA-Z0-9_-.@]/", $_POST['email']) for the email! //I do this part to make sure they don't do anything stupid. //Like if they put "2+2" for the password and "4" for the varpassword, //Then this would stop that from proving true! $password = md5($_POST['password']); $varpassword = md5($_POST['varpassword']); if ($password != $varpassword) { //There passwords did not match //Set a session variable so that you can tell the user how they screwed up $_SESSION['match_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } if ($pass == FALSE) { //They failed the exam! //For some reason they have failed or check system. //You will need to send the back to fix the problem before we continue echo "<meta http-equiv=/"refresh/" content=/"1;url=signup.php/">"; //I like to kill the script at this point. die(); } else { //Hey they past our test! //Looking at all this, I don't know how! lol //You can now change their password into something unreadable. //I do it again to make sure nothing happened to it on the way... $password = md5($_POST['password']); //Now that you have all their info, you can put them into the database //Connect to the database $connect = mysql_connect('localhost',$username,$password) or die(mysql_error()); //Select your database mysql_select_db($database) or die(mysql_error()); //Insert new user $query = mysql_query("INSERT INTO users ('username', 'password', 'email') VALUES ($_POST['username'], $password, $_POST['email'])") or die(mysql_error()); //Close mysql mysql_close(); //Now they have an account! } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-241955 Share on other sites More sharing options...
RitchieGunz Posted April 30, 2007 Author Share Posted April 30, 2007 Can you just give me a little step-by-step and fill in what I filled in wrong?, lol If possible, just give me exactly what I need so I can copy and paste it. Along with signup.php and check.php, should I have any other files in my root directory? Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-241975 Share on other sites More sharing options...
OilSheikh Posted April 30, 2007 Share Posted April 30, 2007 Make sure you have a Databse in PHPMYADMIN in XAMPP first. Makes life easier. In fact, sketch up a Databse design on paper even before that. Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-241979 Share on other sites More sharing options...
bobleny Posted May 1, 2007 Share Posted May 1, 2007 Well, Here you go. Try it and see if it works... signup.php <html> <head> <title>Sign Up</title> </head> <body> <?php echo "<form action=/"check.php/" method=/"post/">" if ($_SESSION['short_username'] == TRUE) { echo "Your username was too short!<br />"; $_SESSION['short_username'] = FALSE; } if ($_SESSION['bad_username'] == TRUE) { echo "Usernames may only contain alphanumeric characters, dashes (-) and underscores (_)<br />"; $_SESSION['bad_username'] = FALSE; } echo "Username: <input type=/"text/" name=/"username/" /><br />" if ($_SESSION['short_password'] == TRUE) { echo "Your password was too short!<br />"; $_SESSION['short_password'] = FALSE; } if ($_SESSION['bad_password'] == TRUE) { echo "Passwords may only contain alphanumeric characters<br />"; $_SESSION['bad_password'] = FALSE; } echo "Password: <input type=/"password/" name=/"password/" /><br />"; if ($_SESSION['match_password'] == TRUE) { echo "Your passwords did not match!<br />"; $_SESSION['match_password'] = FALSE; } echo "Verify Password: <input type=/"password/" name=/"varpassword/" /><br />" if ($_SESSION['bad_email'] == TRUE) { echo "You have entered an invalid E-mail address<br />"; $_SESSION['bad_email'] = FALSE; } echo "E-mail: <input type=/"text/" name=/"email/" /><br />" <input type=/"submit/" value=/"Sign Up/" /> </form> ?> </body> </html> check.php <?php //Database Information //Username? $database_username = "forum"; //Your password? $database_password = "password"; //The name of the database you are trying to connect to $database_database = "users"; //Did the user enter a username? if (strlen($_POST['username']) < 4) { //There username contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['short_username'] = TRUE; //Tell the script that something went wrong $pass = FALSE; { //Did the user enter a password? if (strlen($_POST['password']) < 4) { //There password contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['short_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; { //Did the user enter a email adress? if (strlen($_POST['email']) < { //There email contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_email'] = TRUE; //Tell the script that something went wrong $pass = FALSE; { //Make sure they aren't trying to hack you if (preg_match("/[^a-zA-Z0-9_-]/", $_POST['username'])) { //Their username contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_username'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //Make sure they aren't trying to hack you if (preg_match("/[^a-zA-Z0-9]/", $_POST['password'])) { //Their password contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //Make sure they aren't trying to hack you if (preg_match("/[^a-zA-Z0-9_-.@]/", $_POST['email'])) { //Their email contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_email'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //For added security, MD5 their passwords before you compare them $md5_password = md5($_POST['password']); $md5_varpassword = md5($_POST['varpassword']); //For the usres benifit, make sure their passwords match if ($md5_password != $md5_varpassword) { //There passwords did not match //Set a session variable so that you can tell the user how they screwed up $_SESSION['match_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //If something went wrong, send the back to fix their mistakes if ($pass == FALSE) { //They failed the exam //For some reason they have failed or check system //You will need to send the back to fix the problem before we continue echo "<meta http-equiv=/"refresh/" content=/"1;url=signup.php/">"; //I like to kill the script at this point. die(); } else { //They have entered all the required information //Their username, password, and email are acceptible //For the users pertection, you should always encypt their passwords $password = md5($_POST['password']); //You now have all their info, you may put them into the database //Connect to the database $connect = mysql_connect('localhost',$username,$password) or die(mysql_error()); //Select your database mysql_select_db($database) or die(mysql_error()); //Insert new user $query = mysql_query("INSERT INTO users ('username', 'password', 'email') VALUES ($_POST['username'], $password, $_POST['email'])") or die(mysql_error()); //Close mysql mysql_close(); //They are now signed up //Tell them that are now signed up echo "Congratulations, you are now signed up!"; //Send them back to the home page echo "<meta http-equiv=/"refresh/" content=/"6;url=index.php/">"; //Offer an optional link incase the transfer doesn't work echo "<a href=/"index.php/">If you are not transfered in 10 seconds, click here</a>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242013 Share on other sites More sharing options...
bobleny Posted May 1, 2007 Share Posted May 1, 2007 Do NOT use the code above. Use the one below. I have made a few modifications.... signup.php <html> <head> <title>Sign Up</title> </head> <body> <?php echo "<form action=/"check.php/" method=/"post/">"; if ($_SESSION['short_username'] == TRUE) { echo "Your username was too short!<br />"; $_SESSION['short_username'] = FALSE; } if ($_SESSION['bad_username'] == TRUE) { echo "Usernames may only contain alphanumeric characters, dashes (-) and underscores (_)<br />"; $_SESSION['bad_username'] = FALSE; } echo "Username: <input type=/"text/" name=/"username/" /><br />"; if ($_SESSION['short_password'] == TRUE) { echo "Your password was too short!<br />"; $_SESSION['short_password'] = FALSE; } if ($_SESSION['bad_password'] == TRUE) { echo "Passwords may only contain alphanumeric characters<br />"; $_SESSION['bad_password'] = FALSE; } echo "Password: <input type=/"password/" name=/"password/" /><br />"; if ($_SESSION['match_password'] == TRUE) { echo "Your passwords did not match!<br />"; $_SESSION['match_password'] = FALSE; } echo "Verify Password: <input type=/"password/" name=/"varpassword/" /><br />"; if ($_SESSION['bad_email'] == TRUE) { echo "You have entered an invalid E-mail address<br />"; $_SESSION['bad_email'] = FALSE; } echo "E-mail: <input type=/"text/" name=/"email/" /><br />"; echo "<input type=/"submit/" value=/"Sign Up/" />"; echo "</form>"; ?> </body> </html> check.php <?php //Database Information //Username? $database_username = "username"; //Your password? $database_password = "password"; //The name of the database you are trying to connect to $database_database = "forum"; //Did the user enter a username? if (strlen($_POST['username']) < 4) { //There username contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['short_username'] = TRUE; //Tell the script that something went wrong $pass = FALSE; { //Did the user enter a password? if (strlen($_POST['password']) < 4) { //There password contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['short_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; { //Did the user enter a email address? if (strlen($_POST['email']) < { //There email contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_email'] = TRUE; //Tell the script that something went wrong $pass = FALSE; { //Make sure they aren't trying to hack you if (preg_match("/[^a-zA-Z0-9_-]/", $_POST['username'])) { //Their username contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_username'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //Make sure they aren't trying to hack you if (preg_match("/[^a-zA-Z0-9]/", $_POST['password'])) { //Their password contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //Make sure they aren't trying to hack you if (preg_match("/[^a-zA-Z0-9_-.@]/", $_POST['email'])) { //Their email contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_email'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //For added security, MD5 their passwords before you compare them $md5_password = md5($_POST['password']); $md5_varpassword = md5($_POST['varpassword']); //For the users benefit, make sure their passwords match if ($md5_password != $md5_varpassword) { //There passwords did not match //Set a session variable so that you can tell the user how they screwed up $_SESSION['match_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //If something went wrong, send them back to fix their mistakes if ($pass == FALSE) { //They failed the exam //For some reason they have failed or check system //You will need to send the back to fix the problem before we continue echo "<meta http-equiv=/"refresh/" content=/"1;url=signup.php/">"; //I like to kill the script at this point. die(); } else { //They have entered all the required information //Their username, password, and email are acceptable //For the users protection, you should always encrypt their passwords $password = md5($_POST['password']); //You now have all their info, you may put them into the database //Connect to the database $connect = mysql_connect('localhost', $username, $password) or die(mysql_error()); //Select your database mysql_select_db($database) or die(mysql_error()); //Insert new user $query = mysql_query("INSERT INTO users ('username', 'password', 'email') VALUES ($_POST['username'], $password, $_POST['email'])") or die(mysql_error()); //Close mysql mysql_close(); //They are now signed up //Tell them that they are now signed up echo "Congratulations, you are now signed up!"; //Send them back to the home page echo "<meta http-equiv=/"refresh/" content=/"6;url=index.php/">"; //Offer an optional link in case the transfer doesn't work echo "<a href=/"index.php/">If you are not transfered in 10 seconds, click here</a>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242020 Share on other sites More sharing options...
RitchieGunz Posted May 1, 2007 Author Share Posted May 1, 2007 Thanks alot man. Im suprised you've stayed with me so far and been so helpful But still, there remains a problem. I did all that exactly, changed username to root and left the password blank since its running locally. Problem is, when I view signup.php .. It just shows me some of the php code with a couple field boxes. I would really like to know whats causing this. Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242029 Share on other sites More sharing options...
bobleny Posted May 1, 2007 Share Posted May 1, 2007 That's odd. Try making a new page. test.php <?php echo "Hello, this is just a test."; ?> Run that page and tell me what it gives you. Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242034 Share on other sites More sharing options...
RitchieGunz Posted May 1, 2007 Author Share Posted May 1, 2007 Something is definitely wrong because I just get a blank page :'( Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242035 Share on other sites More sharing options...
AndyB Posted May 1, 2007 Share Posted May 1, 2007 Something is definitely wrong because I just get a blank page :'( Don't "just run that page" ... unless you actually opened a browser and navigated to http://localhost/path/to/that/file php files don't run when opened in isolation, they need to be run on a server. Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242041 Share on other sites More sharing options...
RitchieGunz Posted May 1, 2007 Author Share Posted May 1, 2007 WOW that solved it lol .. And I was 2 seconds away from reinstalling xampp Thank you so much Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242042 Share on other sites More sharing options...
bobleny Posted May 1, 2007 Share Posted May 1, 2007 lol, wow... AndyB to the rescue! I forget that some people don't know about that.... I thought maybe the php wasn't being parsed... Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242046 Share on other sites More sharing options...
RitchieGunz Posted May 1, 2007 Author Share Posted May 1, 2007 Now I get this: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in C:\xampplite\htdocs\xampp\site\signup.php on line 8 I've tried removing characters and testing and it still wont work. <html> <head> <title>Sign Up</title> </head> <body> <?php echo "<form action=/"check.php/" method=/"post/">"; if ($_SESSION['short_username'] == TRUE) Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242071 Share on other sites More sharing options...
john010117 Posted May 1, 2007 Share Posted May 1, 2007 You should put a { after the last line that you've posted. Did you do that? Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242074 Share on other sites More sharing options...
RitchieGunz Posted May 1, 2007 Author Share Posted May 1, 2007 Yea, its already there .. Theres supposedly a problem on the check.php line Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242077 Share on other sites More sharing options...
john010117 Posted May 1, 2007 Share Posted May 1, 2007 Try doing this: <?php echo '<form action="check.php" method="post">'; Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242080 Share on other sites More sharing options...
RitchieGunz Posted May 1, 2007 Author Share Posted May 1, 2007 Thanks, that fixed it. Now I gotta go thru all the lines lol. Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242081 Share on other sites More sharing options...
RitchieGunz Posted May 1, 2007 Author Share Posted May 1, 2007 I was fixing codes fine, I tried googling this with no help: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampplite\htdocs\xampp\site\check.php on line 141 (The 3rd line is line 141) //Insert new user $query = mysql_query("INSERT INTO users ('username', 'password', 'email') VALUES ($_POST['username'], $password, $_POST['email'])") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242090 Share on other sites More sharing options...
john010117 Posted May 1, 2007 Share Posted May 1, 2007 Replace that with this: $username = $_POST['username']; $email = $_POST['email']; $query = mysql_query ("INSERT INTO `users` (username, password, email) VALUES ('$username', '$password', '$email'") OR DIE (mysql_error()); It should work. Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242092 Share on other sites More sharing options...
RitchieGunz Posted May 1, 2007 Author Share Posted May 1, 2007 Parse error: syntax error, unexpected $end in C:\xampplite\htdocs\xampp\site\check.php on line 161 That line is blank. And its after the ?> Am I not closing a funtion? This is the last chunk of lines: //Insert new user $username = $_POST['username']; $email = $_POST['email']; $query = mysql_query ("INSERT INTO `users` (username, password, email) VALUES ('$username', '$password', '$email'") OR DIE (mysql_error()); //Close mysql mysql_close(); //They are now signed up //Tell them that they are now signed up echo "Congratulations, you are now signed up!"; //Send them back to the home page echo '<meta http-equiv="refresh" content="6;url=index.php">'; //Offer an optional link in case the transfer doesn't work echo '<a href="index.php">If you are not transfered in 10 seconds, click here</a>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242098 Share on other sites More sharing options...
RitchieGunz Posted May 1, 2007 Author Share Posted May 1, 2007 This is the whole code: (password is actually blank cause im running locally) <?php //Database Information //Username? $database_username = "root"; //Your password? $database_password = ""; //The name of the database you are trying to connect to $database_database = "members"; //Did the user enter a username? if (strlen($_POST['username']) < 4) { //There username contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['short_username'] = TRUE; //Tell the script that something went wrong $pass = FALSE; { //Did the user enter a password? if (strlen($_POST['password']) < 4) { //There password contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['short_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; { //Did the user enter a email address? if (strlen($_POST['email']) < { //There email contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_email'] = TRUE; //Tell the script that something went wrong $pass = FALSE; { //Make sure they aren't trying to hack you if (preg_match("/[^a-zA-Z0-9_-]/", $_POST['username'])) { //Their username contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_username'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //Make sure they aren't trying to hack you if (preg_match("/[^a-zA-Z0-9]/", $_POST['password'])) { //Their password contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //Make sure they aren't trying to hack you if (preg_match("/[^a-zA-Z0-9_-.@]/", $_POST['email'])) { //Their email contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_email'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //For added security, MD5 their passwords before you compare them $md5_password = md5($_POST['password']); $md5_varpassword = md5($_POST['varpassword']); //For the users benefit, make sure their passwords match if ($md5_password != $md5_varpassword) { //There passwords did not match //Set a session variable so that you can tell the user how they screwed up $_SESSION['match_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //If something went wrong, send them back to fix their mistakes if ($pass == FALSE) { //They failed the exam //For some reason they have failed or check system //You will need to send the back to fix the problem before we continue echo '<meta http-equiv=/"refresh/" content=/"1;url=signup.php/">'; //I like to kill the script at this point. die(); } else { //They have entered all the required information //Their username, password, and email are acceptable //For the users protection, you should always encrypt their passwords $password = md5($_POST['password']); //You now have all their info, you may put them into the database //Connect to the database $connect = mysql_connect('localhost', $username, $password) or die(mysql_error()); //Select your database mysql_select_db($database) or die(mysql_error()); //Insert new user $username = $_POST['username']; $email = $_POST['email']; $query = mysql_query ("INSERT INTO `members` (username, password, email) VALUES ('$username', '$password', '$email'") OR DIE (mysql_error()); //Close mysql mysql_close(); //They are now signed up //Tell them that they are now signed up echo "Congratulations, you are now signed up!"; //Send them back to the home page echo '<meta http-equiv="refresh" content="6;url=index.php">'; //Offer an optional link in case the transfer doesn't work echo '<a href="index.php">If you are not transfered in 10 seconds, click here</a>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242103 Share on other sites More sharing options...
john010117 Posted May 1, 2007 Share Posted May 1, 2007 Try putting a } at the end of the code. That solves most cases. Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242108 Share on other sites More sharing options...
RitchieGunz Posted May 1, 2007 Author Share Posted May 1, 2007 Im starting to catch on little by little .. There were a bunch of { that shoulda been } OK .. So I got the errors outta the way .. after entering some information and mismatchin passwords in the signup.php, it brings me to check.php but its blank. The name of my database is main and I have the table members in there with 4 fields (username, password, email, id) .. Let me know if anything is wrong in the code about that. Thanks. This is how my code looks now: <?php //Database Information //Username? $database_username = "root"; //Your password? $database_password = ""; //The name of the database you are trying to connect to $database_database = "main"; //Did the user enter a username? if (strlen($_POST['username']) < 4) { //There username contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['short_username'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //Did the user enter a password? if (strlen($_POST['password']) < 4) { //There password contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['short_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //Did the user enter a email address? if (strlen($_POST['email']) < { //There email contains less than 4 characters //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_email'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //Make sure they aren't trying to hack you if (preg_match("/[^a-zA-Z0-9_-]/", $_POST['username'])) { //Their username contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_username'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //Make sure they aren't trying to hack you if (preg_match("/[^a-zA-Z0-9]/", $_POST['password'])) { //Their password contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //Make sure they aren't trying to hack you if (preg_match("[^a-zA-Z0-9_-.@]", $_POST['email'])) { //Their email contains invalid characters //They me be trying to hack you... //Set a session variable so that you can tell the user how they screwed up $_SESSION['bad_email'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //For added security, MD5 their passwords before you compare them $md5_password = md5($_POST['password']); $md5_varpassword = md5($_POST['varpassword']); //For the users benefit, make sure their passwords match if ($md5_password != $md5_varpassword) { //There passwords did not match //Set a session variable so that you can tell the user how they screwed up $_SESSION['match_password'] = TRUE; //Tell the script that something went wrong $pass = FALSE; } //If something went wrong, send them back to fix their mistakes if ($pass == FALSE) { //They failed the exam //For some reason they have failed or check system //You will need to send the back to fix the problem before we continue echo '<meta http-equiv=/"refresh/" content=/"1;url=signup.php/">'; //I like to kill the script at this point. die(); } else { //They have entered all the required information //Their username, password, and email are acceptable //For the users protection, you should always encrypt their passwords $password = md5($_POST['password']); //You now have all their info, you may put them into the database //Connect to the database $connect = mysql_connect('localhost', $username, $password) or die(mysql_error()); //Select your database mysql_select_db($database) or die(mysql_error()); //Insert new user $username = $_POST['username']; $email = $_POST['email']; $query = mysql_query ("INSERT INTO `members` (username, password, email) VALUES ('$username', '$password', '$email'") OR DIE (mysql_error()); //Close mysql mysql_close(); //They are now signed up //Tell them that they are now signed up echo "Congratulations, you are now signed up!"; //Send them back to the home page echo '<meta http-equiv="refresh" content="6;url=index.php">'; //Offer an optional link in case the transfer doesn't work echo '<a href="index.php">If you are not transfered in 10 seconds, click here</a>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242117 Share on other sites More sharing options...
bobleny Posted May 1, 2007 Share Posted May 1, 2007 Wow, you sure do a lot when I'm gone! Im starting to catch on little by little .. There were a bunch of { that shoulda been } Sorry about, I copy and pasted the the if statement to make work easier, and it I guess it copyed the error with it... OK .. So I got the errors outta the way .. after entering some information and mismatchin passwords in the signup.php, it brings me to check.php but its blank. The name of my database is main and I have the table members in there with 4 fields (username, password, email, id) .. Let me know if anything is wrong in the code about that. Thanks. I'm sorry for the trouble this has caused you! If my normal linux partition was up, I would have gave you the working script, instead of the one I just typed up in notepad... I should also point out, I have never used the /" before, I thought for sure that would work... Well, I will look this script over again and make sure that it is updated and hopefully you won't get any errors and it will work! Quote Link to comment https://forums.phpfreaks.com/topic/49229-solved-registrationadding-members-to-database/page/2/#findComment-242308 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.