Jump to content

angelali

Members
  • Posts

    128
  • Joined

  • Last visited

    Never

Everything posted by angelali

  1. Guys, it is working now... Pikachu, I mentioned that the problem of duplicate has been solved since you told me about the problem of INDEX in the database. I did mention I created another one and now its working. The only problem was the message to display the user that an email or username has already taken was not displaying. By the way, it is working now, YES, the message is displaying! YES...after 4 hours...the problem is solved.. Here the codes I tried, and which are working great: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['fname']) && isset($_POST['lname'])&& isset($_POST['emailr']) && isset($_POST['user']) && isset($_POST['pass'])) { //Database $connect = @mysql_connect('localhost', 'root', '') or die ('Connection Failed'); @mysql_select_db('registration', $connect) or die ('Connection Failed'); //Assignng variables $firstname = mysql_real_escape_string(stripslashes(trim($_POST['fname']))); $lastname = mysql_real_escape_string(stripslashes(trim($_POST['lname']))); $email = mysql_real_escape_string(stripslashes(trim($_POST['emailr']))); $uname = mysql_real_escape_string(stripslashes(trim($_POST['user']))); $pwd = mysql_real_escape_string(stripslashes(trim($_POST['pass']))); //Registration codes if (empty($firstname) || empty($lastname) || empty($email) || empty($uname) || empty($pwd)) { echo '<p class="error">All fields are required to fill!</p>'; return false; } elseif (strlen($firstname) && (strlen($lastname) < '2')) { echo '<p class="error">Invalid first name or last name!</p>'; return false; } elseif (filter_var($firstname, FILTER_VALIDATE_INT) || (filter_var($lastname, FILTER_VALIDATE_INT))) { echo '<p class="error">First name or last name cannot be integers!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Email address not valid!</p>'; return false; } elseif (strlen($uname) && (strlen($pwd) < '6' )) { echo '<p class="error">Username or password must be minimum 6 characters!</p>'; return false; } else { $pwd = md5($pwd); $query = "INSERT INTO login (id, firstname, lastname, emailaddress, username, password) VALUES('', '$firstname', '$lastname', '$email', '$uname', '$pwd')"; mysql_query($query, $connect); if (mysql_errno($connect)> 0) { echo "The email address or username has already taken, choose another!"; } else { echo '<p class="fail">Successful!</p>'; } } } } ?> I want to thank ALL OF YOU who took so much patience for helping me...ALL OF YOU, THANK YOU VERY MUCH! You have all responded nicely also and as a professional! THANK YOU ALL!
  2. I am new in PHP, and I am learning a lot. My objective is not to become an expert in PHP as I am planning to master MySQL and Oracle later. I have successfully made an image hosting, a mini one, with validations of certain types of files etc...but I am adding a registration form in it which actually I am doing. After trying a lot to solve this problem of duplicate in both username and email address, but in vain, I have decided to include the duplicate of email address, not the username...and it is now working... I want a last help from you guys, I am preventing only duplicate email address now, not both the email and the username, and it is working great. Below are my codes, can you please see them and tell me if from this method, I can also prevent the duplicate of username as well? When I say duplicate here, is the message to display the user that the either the email address or username has already taken. <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['fname']) && isset($_POST['lname'])&& isset($_POST['emailr']) && isset($_POST['user']) && isset($_POST['pass'])) { //Database $connect = @mysql_connect('localhost', 'root', '') or die ('Connection Failed'); @mysql_select_db('registration', $connect) or die ('Connection Failed'); //Assignng variables $firstname = mysql_real_escape_string(stripslashes(trim($_POST['fname']))); $lastname = mysql_real_escape_string(stripslashes(trim($_POST['lname']))); $email = mysql_real_escape_string(stripslashes(trim($_POST['emailr']))); $uname = mysql_real_escape_string(stripslashes(trim($_POST['user']))); $pwd = mysql_real_escape_string(stripslashes(trim($_POST['pass']))); //Registration codes if (empty($firstname) || empty($lastname) || empty($email) || empty($uname) || empty($pwd)) { echo '<p class="error">All fields are required to fill!</p>'; return false; } elseif (strlen($firstname) && (strlen($lastname) < '2')) { echo '<p class="error">Invalid first name or last name!</p>'; return false; } elseif (filter_var($firstname, FILTER_VALIDATE_INT) || (filter_var($lastname, FILTER_VALIDATE_INT))) { echo '<p class="error">First name or last name cannot be integers!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Email address not valid!</p>'; return false; } elseif (strlen($uname) && (strlen($pwd) < '6' )) { echo '<p class="error">Username or password must be minimum 6 characters!</p>'; return false; } else { $pwd = md5($pwd); $query = "INSERT INTO login (id, firstname, lastname, emailaddress, username, password) VALUES('', '$firstname', '$lastname', '$email', '$uname', '$pwd')"; mysql_query($query, $connect); if (mysql_errno($connect)> 0) { echo "Email address already taken"; } else { echo '<p class="fail">Successful!</p>'; } } } } ?>
  3. I successfully corrected the MD5 one. By the way, I inserted it before the INSERT in the codes not in the variables like before... And also, I want to know, if I include the Trim() in the same line as the mysql_real_escape and stripslashes, is it good? Just a question of curiosity, like this: $uname = mysql_real_escape_string(stripslashes(trim($_POST['user'])));
  4. Well, I will try it... By the way, is it necessary to encrypt password in database?
  5. @Drummin, yes I tried that too earlier... and has not worked.. By the way for the password validation, what do you suggest me? I want the password to be encrypted and also it should be a minimum of 6 characters...
  6. Ok I moved my database connection above the variables where are the my_sql_real.... <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['fname']) && isset($_POST['lname'])&& isset($_POST['emailr']) && isset($_POST['user']) && isset($_POST['pass'])) { //Database $connect = @mysql_connect('localhost', 'root', '') or die ('Connection Failed'); @mysql_select_db('registration', $connect) or die ('Connection Failed'); //Assignng variables $firstname = mysql_real_escape_string(stripslashes($_POST['fname'])); $lastname = mysql_real_escape_string(stripslashes($_POST['lname'])); $email = mysql_real_escape_string(stripslashes($_POST['emailr'])); $uname = mysql_real_escape_string(stripslashes($_POST['user'])); $pwd = mysql_real_escape_string(stripslashes($_POST['pass'])); $pmd= md5($pwd);
  7. Here are the latest one: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['fname']) && isset($_POST['lname'])&& isset($_POST['emailr']) && isset($_POST['user']) && isset($_POST['pass'])) { //Assignng variables $firstname = mysql_real_escape_string(stripslashes($_POST['fname'])); $lastname = mysql_real_escape_string(stripslashes($_POST['lname'])); $email = mysql_real_escape_string(stripslashes($_POST['emailr'])); $uname = mysql_real_escape_string(stripslashes($_POST['user'])); $pwd = mysql_real_escape_string(stripslashes($_POST['pass'])); $pmd= md5($pwd); //Database $connect = @mysql_connect('localhost', 'root', '') or die ('Connection Failed'); @mysql_select_db('registration', $connect) or die ('Connection Failed'); //Registration codes if (empty($firstname) || empty($lastname) || empty($email) || empty($uname) || empty($pmd)) { echo '<p class="error">All fields are required to fill!</p>'; return false; } elseif (strlen($firstname) && (strlen($lastname) < '2')) { echo '<p class="error">Invalid first name or last name!</p>'; return false; } elseif (filter_var($firstname, FILTER_VALIDATE_INT) || (filter_var($lastname, FILTER_VALIDATE_INT))) { echo '<p class="error">First name or last name cannot be integers!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Email address not valid!</p>'; return false; } elseif (strlen($uname) && (strlen($pmd) < '6' )) { echo '<p class="error">Username or password must be minimum 6 characters!</p>'; return false; } else { $verify = "SELECT * FROM login WHERE emailaddress = '$email' AND username = '$uname'"; if(mysql_num_rows(mysql_query($verify)) !== 0) { echo '<p class="fail">This email or username is already taken!</p>'; } else { $query = "INSERT INTO login (id, firstname, lastname, emailaddress, username, password) VALUES('', '$firstname', '$lastname', '$email', '$uname', '$pmd')"; mysql_query($query, $connect); echo '<p class="fail">Successful!</p>'; } } } } ?> Here is the one which worked earlier but that that warning message: Warning: mysql_num_rows() expects parameter 1 to be resource, string given in C:\xampp\htdocs\miniimagehosting\register.php on line 60 if(mysql_num_rows($verify) !== 0)
  8. there is no mistake in my database, else the code I did earlier would not work even im getting this warning message...
  9. @drummin, I did try but dont know why it is not working on mine... Implement it in my codes and try it...you will see it is not working..
  10. I am not getting duplicate contents anymore, the only problem remains is that the message to show the user that an email address or a username has already taken is not displaying.. To do that, I have to read the rows in the fields of both email address and the username in the table Login, that's why I did this. The user should know if an email or username has already taken...
  11. yes i tried, but not work.. :'( Oh God, why ???/ It has been 3 hours I'm on this...
  12. I tried your query, but now it is becoming like before, I mean, it is saving even the email or username ias already taken.. Seriously, I have found many people encounter this problem of checking...
  13. But in some ebooks and also in some video tutorials i have read and watched, they did the same...
  14. Guys, I changed the codes, it is working but I got this warning: Warning: mysql_num_rows() expects parameter 1 to be resource, string given in C:\xampp\htdocs\miniimagehosting\register.php on line 61 <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['fname']) && isset($_POST['lname'])&& isset($_POST['emailr']) && isset($_POST['user']) && isset($_POST['pass'])) { //Assignng variables $firstname = mysql_real_escape_string(stripslashes($_POST['fname'])); $lastname = mysql_real_escape_string(stripslashes($_POST['lname'])); $email = mysql_real_escape_string(stripslashes($_POST['emailr'])); $uname = mysql_real_escape_string(stripslashes($_POST['user'])); $pwd = mysql_real_escape_string(stripslashes($_POST['pass'])); $pmd= md5($pwd); //Database $connect = mysql_connect('localhost', 'root', '') or die ('Connection Failed'); mysql_select_db('registration', $connect) or die ('Connection Failed'); //Registration codes if (empty($firstname) || empty($lastname) || empty($email) || empty($uname) || empty($pmd)) { echo '<p class="error">All fields are required to fill!</p>'; return false; } elseif (strlen($firstname) && (strlen($lastname) < '2')) { echo '<p class="error">Invalid first name or last name!</p>'; return false; } elseif (filter_var($firstname, FILTER_VALIDATE_INT) || (filter_var($lastname, FILTER_VALIDATE_INT))) { echo '<p class="error">First name or last name cannot be integers!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Email address not valid!</p>'; return false; } elseif (strlen($uname) && (strlen($pmd) < '6' )) { echo '<p class="error">Username or password must be minimum 6 characters!</p>'; return false; } else { $verify = "SELECT * FROM login WHERE emailaddress = '$email' AND username = '$uname'"; if(mysql_num_rows($verify) !== 0) { echo '<p class="fail">This email or username is already taken!</p>'; } else { $query = "INSERT INTO login (id, firstname, lastname, emailaddress, username, password) VALUES('', '$firstname', '$lastname', '$email', '$uname', '$pmd')"; mysql_query($query, $connect); echo '<p class="fail">Successful!</p>'; } } } } ?>
  15. @Drummin, nope does not work! I did code a similar thing some days ago, and I did (mysql_errno($db)> 0) and it worked in another website, but it is not working in this one, thus I used another way...like you see above in the codes...
  16. You mean when declaring its variable above, I should insert the Trim in it? I did it like this: $uname = mysql_real_escape_string(trim($_POST['user']));
  17. I recreated it and it is working now. No duplicate content But now, I will try the code you suggested, so that I can notify the user about the duplication...
  18. So, if I understand well, I should make only one field UNIQUE right? And it is the email address only to be unique but not the username?
  19. I have re-created the database, here is your results now: CREATE TABLE `login` ( `id` int(11) NOT NULL AUTO_INCREMENT, `firstname` varchar(50) NOT NULL, `lastname` varchar(50) NOT NULL, `emailaddress` varchar(50) NOT NULL, `username` varchar(50) NOT NULL, `password` varchar(50) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `emailaddress` (`emailaddress`,`username`) ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=latin1
  20. Here they are: CREATE TABLE `login` ( `id` int(11) NOT NULL AUTO_INCREMENT, `firstname` varchar(50) NOT NULL, `lastname` varchar(50) NOT NULL, `emailaddress` varchar(50) NOT NULL, `username` varchar(50) NOT NULL, `password` varchar(50) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `emailaddress` (`emailaddress`,`username`), UNIQUE KEY `username` (`username`), UNIQUE KEY `emailaddress_2` (`emailaddress`,`username`), UNIQUE KEY `emailaddress_3` (`emailaddress`,`username`) ) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=latin1
  21. huhh... I got this #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CREATE TABLE login' at line 1
  22. Pikachu, I corrected it, can you tell me the other errors...as duplicate email addresses and username are still being saved...
  23. Dude, thank you for replying, I swear to God, I swear to God that before I posted this issue here, I did put the "AND", but I got the error and even Dreamweaver told me it was an error. But anyway, I did it again and now it is working and also not working... I mean sometimes it is not storing in the database and notifies the user his email address is already taken and sometimes it is saving without notification. Why? I want to know also one thing, even I put the two fields which are the email address and username as UNIQUE key, why duplicate content is still stored? It's weird! Here are my codes again, I changed it: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['fname']) && isset($_POST['lname'])&& isset($_POST['emailr']) && isset($_POST['user']) && isset($_POST['pass'])) { //Assignng variables $firstname = mysql_real_escape_string($_POST['fname']); $lastname = mysql_real_escape_string($_POST['lname']); $email = mysql_real_escape_string($_POST['emailr']); $uname = mysql_real_escape_string($_POST['user']); $pwd = mysql_real_escape_string($_POST['pass']); $pmd= md5($pwd); //Database $connect = mysql_connect('localhost', 'root', '') or die ('Connection Failed'); mysql_select_db('registration', $connect) or die ('Connection Failed'); //Registration codes if (empty($firstname) || empty($lastname) || empty($email) || empty($uname) || empty($pmd)) { echo '<p class="error">All fields are required to fill!</p>'; return false; } elseif (strlen($firstname) && (strlen($lastname) < '2')) { echo '<p class="error">Invalid first name or last name!</p>'; return false; } elseif (filter_var($firstname, FILTER_VALIDATE_INT) || (filter_var($lastname, FILTER_VALIDATE_INT))) { echo '<p class="error">First name or last name cannot be integers!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Email address not valid!</p>'; return false; } elseif (strlen($uname) && (strlen($pmd) < '6' )) { echo '<p class="error">Username or password must be minimum 6 characters!</p>'; return false; } else { $verify = "SELECT * FROM login WHERE emailaddress = '$email' AND username = '$uname'"; if (mysql_num_rows(mysql_query($verify))) { echo '<p class="fail">This email or username is already taken!</p>'; } else { $query = "INSERT INTO login (id, firstname, lastname, emailaddress, username, password) VALUES('', '$firstname', '$lastname', '$email', '$uname', '$pmd')"; mysql_query($query, $connect); } } } } ?>
  24. I am having a big problem in MySQL and a part in my PHP coding as well. I created a registration form, where the user will have to fill his names, email address, choose a username and so on. I do not want duplicate email address and username in my database, thus, if a user choose either an email address or a username which has already taken, he will be notified. To prevent this duplication, I have set both the email address and username fields as UNIQUE KEY in MySQL. My problems are: Even by setting both the username and email address fields as UNIQUE KEY, it is not working as I can register using the same email address or username. How to solve this? I have coded also to prevent this problem of duplicate so that the user will be notified to choose another email or username, but I am having a warning. My PHP codes: <?php if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['fname']) && isset($_POST['lname'])&& isset($_POST['emailr']) && isset($_POST['user']) && isset($_POST['pass'])) { //Assignng variables $firstname = mysql_real_escape_string($_POST['fname']); $lastname = mysql_real_escape_string($_POST['lname']); $email = mysql_real_escape_string($_POST['emailr']); $uname = mysql_real_escape_string($_POST['user']); $pwd = mysql_real_escape_string($_POST['pass']); $pmd= md5($pwd); //Database $connect = mysql_connect('localhost', 'root', '') or die ('Connection Failed'); mysql_select_db('registration', $connect) or die ('Connection Failed'); //Registration codes if (empty($firstname) || empty($lastname) || empty($email) || empty($uname) || empty($pmd)) { echo '<p class="error">All fields are required to fill!</p>'; return false; } elseif (strlen($firstname) && (strlen($lastname) < '2')) { echo '<p class="error">Invalid first name or last name!</p>'; return false; } elseif (filter_var($firstname, FILTER_VALIDATE_INT) || (filter_var($lastname, FILTER_VALIDATE_INT))) { echo '<p class="error">First name or last name cannot be integers!</p>'; return false; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { echo '<p class="error">Email address not valid!</p>'; return false; } elseif (strlen($uname) && (strlen($pmd) < '6' )) { echo '<p class="error">Username or password must be minimum 6 characters!</p>'; return false; } else { $query = "INSERT INTO login (id, firstname, lastname, emailaddress, username, password) VALUES('', '$firstname', '$lastname', '$email', '$uname', '$pmd')"; mysql_query($query, $connect); if (mysql_num_rows(mysql_query("SELECT * FROM login WHERE emailaddress = '$email' username = '$uname'"))) { echo '<p class="fail">This email or username is already taken!</p>'; } } } } ?> The warning message I am getting: Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\miniimagehosting\register.php on line 44
×
×
  • Create New...

Important Information

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.