samoi Posted October 22, 2008 Share Posted October 22, 2008 Hello guys, I'm new to this forum, and I really like the way you help beginners and intermediate php coders! Actually, here is my script! <?php // make a conncetion. $conn = mysql_connect("localhost","root","pass"); $db = mysql_select_db("samoi"); $username = clean($_POST['username']); $email = clean($_POST['email']); $password = clean($_POST['password']); $encpass = md5($password); $checkuserSQL = "SELECT * FROM users WHERE username = '$username'"; $checkinguser = mysql_query($checkuserSQL); $checkemailSQL = "SELECT * FROM users WHERE email = '$email'"; $checkingemail = mysql_query($checkemailSQL); if(!$username || !$email || !$password) { echo("All fields are required, please go back and insert them ALL"); } elseif(mysql_num_rows($checkinguser) > 0 ) { echo("the user name $username is already registered, have another one please!"); } elseif(mysql_num_rows($checkingemail) > 0 ) { echo("The email $email is in use!!!"); } else{ $inserting = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$encpass')"; $result= mysql_query($inserting); echo("Welcome $username <br> You Are Now Registered!"); } function clean($str) {return mysql_escape_string($str);} ?> I need some verification for the email! I mean when a user enter an email like this 'alsdjkhflghdks' I need the script to stop the user and echo(" Please make sure you typed in a valid email address"); what kind of [if(statment)] should I put there? or what ever you call it I'm new to the PHP, so please be clear as possible! forgive my english, I'm an international student! Thank you guys in advance! Quote Link to comment https://forums.phpfreaks.com/topic/129666-solved-i-need-an-email-verification-with-my-signup-script/ Share on other sites More sharing options...
CroNiX Posted October 22, 2008 Share Posted October 22, 2008 if(ereg ("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$", $email)){ //email is in valid format } else { //its not valid } Quote Link to comment https://forums.phpfreaks.com/topic/129666-solved-i-need-an-email-verification-with-my-signup-script/#findComment-672301 Share on other sites More sharing options...
samoi Posted October 22, 2008 Author Share Posted October 22, 2008 if(ereg ("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$", $email)){ //email is in valid format } else { //its not valid } Wow, very fast reply, amazing forums! first of all, thank you very much CroNiX for helping me But can you add it to the script, so that I can learn how to do it because I have a function already, and I dont know how to put this into it! Thank you, and I'm sorry if I bothered you! Quote Link to comment https://forums.phpfreaks.com/topic/129666-solved-i-need-an-email-verification-with-my-signup-script/#findComment-672308 Share on other sites More sharing options...
samoi Posted October 23, 2008 Author Share Posted October 23, 2008 Wow, very fast reply, amazing forums! Quote Link to comment https://forums.phpfreaks.com/topic/129666-solved-i-need-an-email-verification-with-my-signup-script/#findComment-672339 Share on other sites More sharing options...
samoi Posted October 23, 2008 Author Share Posted October 23, 2008 Any help guys? Quote Link to comment https://forums.phpfreaks.com/topic/129666-solved-i-need-an-email-verification-with-my-signup-script/#findComment-672481 Share on other sites More sharing options...
CroNiX Posted October 23, 2008 Share Posted October 23, 2008 I did the hard part...now you should learn and attempt the easy part. Its basic php and using the code you already supplied it shouldn't be too hard to figure it out. You won't learn if I just do it for you (which is what this site is about...learning). Ill just give you a hint...its going to start with elseif( ... Quote Link to comment https://forums.phpfreaks.com/topic/129666-solved-i-need-an-email-verification-with-my-signup-script/#findComment-672506 Share on other sites More sharing options...
samoi Posted October 23, 2008 Author Share Posted October 23, 2008 I did the hard part...now you should learn and attempt the easy part. Its basic php and using the code you already supplied it shouldn't be too hard to figure it out. You won't learn if I just do it for you (which is what this site is about...learning). Ill just give you a hint...its going to start with elseif( ... I'm sorry man, I didn't mean that! But I want you to understand me since I'm a beginner to the php language! Ok, don't think that I didn't tried it so many times and different attempts to get the codes work! but I get error! here is an example! // this code is taken from the page! if(!$username || !$email || !$password) { echo("All fields are required, please go back and insert them all"); } elseif(mysql_num_rows($checkinguser) > 0 ) { echo("the user name $username is allready rigestered, have another one please!"); } elseif(ereg ("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$", $email)){ echo(""); // echo nothing because I don't want it to mention anything! else{ echo(" You entered a not valid email address, go back"); // this is what is required! } } elseif(mysql_num_rows($checkingemail) > 0 ) { echo("The email $email is in use!!!"); } else{ $inserting = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$encpass')"; $result= mysql_query($inserting); echo("Welcome $username <br> You Are Now Registered!"); } I get this this error Parse error: syntax error, unexpected T_ELSE in /Applications/MAMP/htdocs/2.php on line 32 Quote Link to comment https://forums.phpfreaks.com/topic/129666-solved-i-need-an-email-verification-with-my-signup-script/#findComment-672514 Share on other sites More sharing options...
CroNiX Posted October 23, 2008 Share Posted October 23, 2008 You almost had it. I will simplify it so that you don't have to have the extra else as its not needed (as noted by your comment) <?php // this code is taken from the page! if(!$username || !$email || !$password) { echo("All fields are required, please go back and insert them all"); } elseif(mysql_num_rows($checkinguser) > 0 ) { echo("the user name $username is allready rigestered, have another one please!"); } elseif(!ereg ("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$", $email)){ echo(" You entered a not valid email address, go back"); // this is what is required! } elseif(mysql_num_rows($checkingemail) > 0 ) { echo("The email $email is in use!!!"); } else{ $inserting = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$encpass')"; $result= mysql_query($inserting); echo("Welcome $username <br> You Are Now Registered!"); } Notice the ! in front of the ereg expression, meaning NOT. I also indented your code. It makes it a lot easier to read and is good programming practice. Quote Link to comment https://forums.phpfreaks.com/topic/129666-solved-i-need-an-email-verification-with-my-signup-script/#findComment-672524 Share on other sites More sharing options...
samoi Posted October 23, 2008 Author Share Posted October 23, 2008 You almost had it. I will simplify it so that you don't have to have the extra else as its not needed (as noted by your comment) <?php // this code is taken from the page! if(!$username || !$email || !$password) { echo("All fields are required, please go back and insert them all"); } elseif(mysql_num_rows($checkinguser) > 0 ) { echo("the user name $username is allready rigestered, have another one please!"); } elseif(!ereg ("^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$", $email)){ echo(" You entered a not valid email address, go back"); // this is what is required! } elseif(mysql_num_rows($checkingemail) > 0 ) { echo("The email $email is in use!!!"); } else{ $inserting = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$encpass')"; $result= mysql_query($inserting); echo("Welcome $username <br> You Are Now Registered!"); } Notice the ! in front of the ereg expression, meaning NOT. I also indented your code. It makes it a lot easier to read and is good programming practice. Maan, You are awesome ! I knew it's going to work for now! since I forgot the ! symbol is considering as NOT, let me tell you this, I'm teaching my self through eBook, called sams teaches you PHP, MySQL, and apache in 24 hours, and I learned this != Non-equivalence Left is not equivalent to right $x != 5 true and I did it in the first statement of if !$username ,,,, etc. but i thought this ! only work for variables and not for expressions like !expression(the command) I learned a new thing about ! expression, and the code to authentication emails! Thank you very much man, and my apologize for disturbing you. note: I really hate the way that PHP.com/manual teaches, so I came here. If my registration here will lead me to break the rules, I would love my userID to be banned! for moderatores, My problem is solved by CroNix, many thanks to him for his help Quote Link to comment https://forums.phpfreaks.com/topic/129666-solved-i-need-an-email-verification-with-my-signup-script/#findComment-672534 Share on other sites More sharing options...
CroNiX Posted October 23, 2008 Share Posted October 23, 2008 No problem, you didn't disturb me or anyone else. That's what the site is about...asking questions and helping others. People just want to see that you try, and if you don't get it they will help. There should be a 'Solved' button below the post that you can click to mark this topic as solved. Quote Link to comment https://forums.phpfreaks.com/topic/129666-solved-i-need-an-email-verification-with-my-signup-script/#findComment-672538 Share on other sites More sharing options...
samoi Posted October 23, 2008 Author Share Posted October 23, 2008 No problem, you didn't disturb me or anyone else. That's what the site is about...asking questions and helping others. People just want to see that you try, and if you don't get it they will help. There should be a 'Solved' button below the post that you can click to mark this topic as solved. I learned a gain I hit the button and it marked it as SOLVED. Thank you so much, now I will go and work for the login codes, hopfully I can get it by myself. many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/129666-solved-i-need-an-email-verification-with-my-signup-script/#findComment-672540 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.