Jump to content

[SOLVED] I need an email verification with my Signup script!


samoi

Recommended Posts

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!

:)

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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( ...

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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  :)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.