Jump to content

Validation


ChompGator

Recommended Posts

Boy do I have lots of PHP Questions today, Im only posting one at a time though so I have time to write my scripts and understand them. I was wondering if someone could help me out, or point me to a tutorial online, what I did was make a 'join this website' link, and Ive already made the form - and what I want to happen is when the user clicks the submit button, the server sends them an email with a link to validate their account once they click the link, they have been added to the "Master Member List"

 

I already have the form, and the handleform.php (the script that handles the form.htm) entering their data into the database, but only once they click the validation link that is sent to them, they are added to the master list.

 

Does anyone know a script for a validation link that I can add to my script?

 

Thank

Link to comment
Share on other sites

I had the same problem before and I found a script in a book I had.  Here is my code with the email verification in it.  You need to setup your database for the login table to have a field to set if active or not.

 

 

<?php 
session_start();
include 'dbconnect.php';



if($_POST['Submit']) {
$myusername=$_POST['myusername'];

$mypassword=$_POST['mypassword'];



$sql="SELECT * FROM login WHERE username='$myusername' and password='$mypassword'";

$result=mysql_query($sql);



// Mysql_num_row is counting table row

$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row



if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"

session_register("myusername");

session_register("mypassword");

header("location:ad_setup.php");

}

else {
echo "<div id='error_setup'>The account information does not exist, Try again!</div>";

}

ob_end_flush();

}


if($_POST['create']) {
    if($_POST['password1'] == $_POST['password2']) {
        $checksql = "SELECT * FROM login WHERE username = '" . $_POST['username'] . "';";
        $checkresult = mysql_query($checksql);
        $checknumrows = mysql_num_rows($checkresult);
        
        if($checknumrows == 1) {
            header("Location: http://www.garagesalelister.com/account_setup.php?error=taken");

            }
        else {
              for($i = 0; $i < 16; $i++) {
                 $randomstring .= chr(mt_rand(32,126));
              }
                    
            $verifyurl = "http://www.garagesalelister.com/verify.php";
            $verifystring = urlencode($randomstring);
            $verifyemail = urlencode($_POST['email']);
            $validusername = $_POST['username'];
            
            $sql = "INSERT INTO login(username, password, email, verifystring, active)
            VALUES('" . $_POST['username'] . "', '" . $_POST['password1'] . "', '" . $_POST['email'] . "', '" . 			addslashes($randomstring) . "', 0);";
            mysql_query($sql);




            
$mail_body=<<<_MAIL_
                    
  Hi $validusername, Thank you for registering with Garage Sale Lister.  Please click on the following link to verify your new account:
     $verifyurl?email=$verifyemail&verify=$verifystring
                    
_MAIL_;
            
  mail($_POST['email'], "Garage Sale Lister User Verification", $mail_body);
            
  echo "A link has been emailed to the address you entered below. Please follow the link in the email to validate your account and to
        start posting your Garage Sale Items now.";
        }
       }
    else {
        header("Location: http://www.garagesalelister.com/account_setup.php?error=pass");

    }
}
else {
    switch($_GET['error']) {
    case "pass":
        echo "<div id='error_setup'>Passwords do not match!</div>";
        break;
    
    case "taken":
        echo "<div id='error_setup'>Username taken, please use another.</div>";
        break;
    
    case "no":
        echo "<div id='error_setup'>Incorrect login details!</div>";
        break;
    }
    
} 
?>	


Link to comment
Share on other sites

Ok, before I add my big form, Im just trying to do a test form just with 3 simple fields, "username" "password" "email"

So below is new.htm

and then the php document that is supposed to handle the form is  new.htm, the name of the php document is "email.php

Im submitting the form and its just taking me to a page cannot be displayed - I do have a dbconnect.php (that is stated at the start of the php document.) - What do you see wrong with this code that I can fix?

 

new.htm

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
<form name="input" action="email.php"
method="post">
Username: 
<input type="text" name="user"><br />
Password: 
<input type="text" name="user0"><br />
Email        
<input type="text" name="user1"><br />
<br />
 <input type="submit" value="Submit">
</form>
</body>

</html>

 

email.php

<?php 
session_start();
include 'dbconnect.php';



if($_POST['Submit']) {
$myusername=$_POST['myusername'];

$mypassword=$_POST['mypassword'];



$sql="SELECT * FROM join WHERE username='$myusername' and password='$mypassword'";

$result=mysql_query($sql);



// Mysql_num_row is counting table row

$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row



if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"

session_register("myusername");

session_register("mypassword");

header("location:ad_setup.php");

}

else {
echo "<div id='error_setup'>The account information does not exist, Try again!</div>";

}

ob_end_flush();

}


if($_POST['create']) {
    if($_POST['password1'] == $_POST['password2']) {
        $checksql = "SELECT * FROM join WHERE username = '" . $_POST['username'] . "';";
        $checkresult = mysql_query($checksql);
        $checknumrows = mysql_num_rows($checkresult);

            }
        else {
              for($i = 0; $i < 16; $i++) {
                 $randomstring .= chr(mt_rand(32,126));
              }
                    
            $verifyurl = "http://www.jetbluevirtual.net/join/verify.php";
            $verifystring = urlencode($randomstring);
            $verifyemail = urlencode($_POST['email']);
            $validusername = $_POST['username'];
            
            $sql = "INSERT INTO join(username, password, email, verifystring, active)
            VALUES('" . $_POST['username'] . "', '" . $_POST['password1'] . "', '" . $_POST['email'] . "', '" . 			addslashes($randomstring) . "', 0);";
            mysql_query($sql);




            
$mail_body=<<<_MAIL_
                    
  Hi $validusername, Welcome To JBU  Please click on the following link to verify your new account:
     $verifyurl?email=$verifyemail&verify=$verifystring
                    
_MAIL_;
            
  mail($_POST['email'], "JBU", $mail_body);
            
  echo "A link has been emailed to the address you entered. Please see the email - to activate your account";
        }
       }
       
else {
    switch($_GET['error']) {
    case "pass":
        echo "<div id='error_setup'>Passwords do not match!</div>";
        break;
    
    case "taken":
        echo "<div id='error_setup'>Username taken, please use another.</div>";
        break;
    
    case "no":
        echo "<div id='error_setup'>Incorrect login details!</div>";
        break;
    }
    
} 
?>

 

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.