Jump to content

Help on E-mail Activation


tuxbuddy

Recommended Posts

Hello PHPfreakers,

I need your help regarding the Email Activation.I have written a code which sends the link once any user register for an account.

 

 

 

 

File : insert.php

<?php



$firstname=$_POST['firstname'];

$surname=$_POST['surname'];

$email=$_POST['email'];

$password=$_POST['password'];

$loginname=$_POST['loginname'];

$telnr=$_POST['telnr'];

$rooms_id=$_POST['rooms_id'];

$organisation_id=$_POST['organisation_id'];

$middlename=$_POST['middlename'];

$group_id=$_POST['group_id'];

$department_id=$_POST['department_id'];

$loc_telnr=$_POST['loc_telnr'];

$title=$_POST['title'];

$first_letters=$_POST['first_letters'];





$con = mysql_connect("localhost","root","mysql123");

if (!$con)

 {

 die('Could not connect: ' . mysql_error());

 }mysql_select_db("helpcore", $con);





$sql="INSERT INTO member (firstname, surname, email, password, is_admin, loginname, personeelsnummer, allowed_to_log_in, telnr, rooms_id, may_log_in, ip, session_key, last_contact, initial_contact, last_visited_page, organisation_id, middlename, group_id, department_id, building_id, loc_telnr, global_view, sla_level_id, title, first_letters, session_use_alerts,notes)

VALUES ('$firstname','$surname','$email','$password',0,'$loginname',NULL,NULL,'$telnr','$rooms_id',0,'127.0.0.1',NULL,'0000-00-00 00:00:00','0000-00-00 00:00:00',NULL,NULL,'$middlename',NULL,NULL,NULL,'$loc_telnr',0,0,'$title','$first_letters',0,'GET')";




$result=mysql_query($sql);

if($result){

#if (!mysql_query($sql,$con))

#  {

#  die('Error: ' . mysql_error());

#  }



#include("banner.gif");

#include("mailing.php");

#echo "Thanks for the Registration.Your Record has been sent for Approval.Kindly wait for the PETP Approval Mail";

$to="ajeet.singh.raina@logicacmg.com";



// Your subject

$subject="Activation Request Mail";



// From

$header="This mail is automatically generated from PETP-INSTALL NEW TICKET TRACKIING TOOl ";



// Your message

$message="A New User has registered for an account\n";

$message="This mail is regarding a New User Account Activation \r\n";

$message.="Click on this link to activate his account \r\n";

$message.="http://10.14.2.36/petp/activation.php[color=red]?[font=Verdana]passkey=$loginname";[/font][/color]


// send email

$sentmail = mail($to,$subject,$header,$message);



//mail(ajeet.singh.raina@logica.com,Test,Test,test);

//echo " Kindly Check your mail for final arrpoval status";

}



// if not found

else {

echo "Not found your email in our database";

}



// if your email succesfully sent

if($sentmail){

echo "Thanks for the Registration\n.";

echo "You will soon receive an activation mail from INSTALL TEAM.";

}

else {

echo "Cannot send Confirmation link to your e-mail address";

}

mysql_close($con)

?>

 

 

 

 

 

The above code will send the mail to one of user.After that, he will click on this link and opens up the first next file.

 

Now comes the next file which will display the radio button either to activate or de-activate.IN address bar the passkey is there(THE MAIN POINT OF INTEREST)

File : activation.php

<html><table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">

<p>

<body bgcolor="#d0d0d0">



<img src="helpcore.jpg" align="center">

</p>



<tr>

<form name="form1" method="post" action="migrate.php">

<td>

<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">

<tr>

<td colspan="3"><strong>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<u>Activation Form </u></strong></td>

</tr>

<tr>

<td width="78">Activate</td>

<td width="6">:</td>

<td width="294">

<Input type ='radio' Name ='gender' value='activate'>





</td>

</tr>

<tr>



<td width="78">Deactivate</td>

<td width="6">:</td>

<td width="310">

<Input type ='radio' Name='gender' value='deactivate'>







<tr>

<td> </td>

<td> </td>

<td><input type="submit" name="Submit1" value="Submit"></td>

</tr>



</table>

</td>

</form>

</tr></tr>

</table>

</html>

 

Now we have the last PHP Code which will migrate the data from the temporary tAble to Actual table(GEnrally in Email Activation this is common fundamenta that first data is stored in temporary table(HERE "member" table) and then gets migrated once activated by the user(here "users table)

 

File : migrate.php

File : migrate.php



<?PHP

include('config.php');

echo "$host";

$passkey=$_GET['passkey'];

echo "$passkey";

#$activate_status = 'unchecked';

#$deactivate_status = 'unchecked';

echo "Hai";

echo "Welcome";

echo $_POST['gender'];

if ($_POST['gender']=='activate')

{



$tbl_name1="member";

$sql1="Select * from $tbl_name1 where loginname='$passkey'";

echo "$sql1";

#$result1=mysql_query($sql1);

#echo "$result1";

// If successfully queried

if($result1)

   {



// Count how many row has this passkey

$count=mysql_num_rows($result1);

#echo "$count";

// if found this passkey in our database, retrieve data from table "temp_members_db"

/*if($count==1)

      {



$rows=mysql_fetch_array($result1);

$firstname=$_POST['firstname'];

$surname=$_POST['surname'];

$email=$_POST['email'];

$password=$_POST['password'];

$loginname=$_POST['loginname'];

$telnr=$_POST['telnr'];

$rooms_id=$_POST['rooms_id'];

$organisation_id=$_POST['organisation_id'];

$middlename=$_POST['middlename'];

$group_id=$_POST['group_id'];

$department_id=$_POST['department_id'];

$loc_telnr=$_POST['loc_telnr'];

$title=$_POST['title'];

$loc_telnr=$_POST['loc_telnr'];

$title=$_POST['title'];

$first_letters=$_POST['first_letters'];



$tbl_name2="users";

$sql2="INSERT INTO $tbl_name2 (firstname, surname, email, password, is_admin, loginname, personeelsnummer, allowed_to_log_in, telnr, rooms_id, may_log_in, ip, session_key, last_contact, initial_contact, last_visited_page, organisation_id, middlename, group_id, department_id, building_id, loc_telnr, global_view, sla_level_id, title, first_letters, session_use_alerts,notes)

VALUES ('$firstname','$surname','$email','$password',0,'$loginname',NULL,NULL,'$telnr','$rooms_id',0,'127.0.0.1',NULL,'0000-00-00 00:00:00','0000-00-00 00:00:00',NULL,NULL,'$middlename',NULL,NULL,NULL,'$loc_telnr',0,0,'$title','$first_letters',0,'GET')";






$result2=mysql_query($sql2);

     }



// if not found passkey, display message "Wrong Confirmation code"

else

    {

echo "Wrong Confirmation code";

    }

// if successfully moved data from table"member" to table "users" displays message "Your account has been activated" and don't forget to delete confirmation code from table "temp_members_db"

if($result2)

{



echo "The account has been activated";



// Delete information of this user from table "temp_members_db" that has this passkey

$sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";

$result3=mysql_query($sql3);



}



}*/





}

elseif ($_POST['gender']=='deactivate')

{

echo "Deactivate Selected";

}

 

 

All I run the above on browser it is not taking passkey output.

Especially,

the line:

<?PHP

 

include('config.php');

 

echo "$host";

 

$passkey=$_GET['passkey'];

 

echo "$passkey";

 

 

The Output it is showing is :

localhostHAi Welcome Select * from member where loginname=''

Link to comment
Share on other sites

what? (personally i use a single table for users wether activated or not - just change a value from 0 to 1 when activated - saves an table).

 

i dont really understandyour problem, but ill guess that $_GET['passkey'] is returnign null.

 

If so then it's either not in the URL, or it is not spelled correctly, use print_r($_GET); to get all the available $_GET variables.

Link to comment
Share on other sites

Thanks for the reply.Lemme tel you the exact issue I am facing.

I am using Tool called HelpCORE.It has database called helpcore in which there is one table "users" which keeps the DB of credentials.I dont want to disturb the table.So WhatI need is creating a temporary table for users registration.After the user sumbits the form he will receive a mail for activation.Now when he clicks on Activation Link on his mail the overall table gets shifted to tool's table called USers.

So I have only that option no 1 or 0 stuffs.

So plis go through the code and help me out.

 

Link to comment
Share on other sites

ohhhh ok lol.

 

change this (in activation.php):

<form name="form1" method="post" action="migrate.php">

 

to this:

<form name="form1" method="post" action="migrate.php?passkey=<?php echo($_GET['passkey']); ?>">

 

you need to carry the passkey onto migrate.php otherwise migrate.php wont know what your on about ;)

Link to comment
Share on other sites

You are Simply a Brilliant Guy...

 

Its Working Maan....I need one more help...Do you think the migrate.php gonna work...I mean Is my Logic Correct???

I have commented lots of lines...Pls Do check if it gonna work...or not.

 

Here all after uncommenting:

 

File : migrate.php



<?PHP

include('config.php');

echo "$host";

$passkey=$_GET['passkey'];

echo "$passkey";

#$activate_status = 'unchecked';

#$deactivate_status = 'unchecked';

echo "Hai";

echo "Welcome";

echo $_POST['gender'];

if ($_POST['gender']=='activate')

{



$tbl_name1="member";

$sql1="Select * from $tbl_name1 where loginname='$passkey'";



$result1=mysql_query($sql1);



// If successfully queried

if($result1)

    {



// Count how many row has this passkey

$count=mysql_num_rows($result1);



// if found this passkey in our database, retrieve data from table "temp_members_db"

if($count==1)

       {



$rows=mysql_fetch_array($result1);

$firstname=$_POST['firstname'];

$surname=$_POST['surname'];

$email=$_POST['email'];

$password=$_POST['password'];

$loginname=$_POST['loginname'];

$telnr=$_POST['telnr'];

$rooms_id=$_POST['rooms_id'];

$organisation_id=$_POST['organisation_id'];

$middlename=$_POST['middlename'];

$group_id=$_POST['group_id'];

$department_id=$_POST['department_id'];

$loc_telnr=$_POST['loc_telnr'];

$title=$_POST['title'];

$loc_telnr=$_POST['loc_telnr'];

$title=$_POST['title'];

$first_letters=$_POST['first_letters'];



$tbl_name2="users";

$sql2="INSERT INTO $tbl_name2 (firstname, surname, email, password, is_admin, loginname, personeelsnummer, allowed_to_log_in, telnr, rooms_id, may_log_in, ip, session_key, last_contact, initial_contact, last_visited_page, organisation_id, middlename, group_id, department_id, building_id, loc_telnr, global_view, sla_level_id, title, first_letters, session_use_alerts,notes)

VALUES ('$firstname','$surname','$email','$password',0,'$loginname',NULL,NULL,'$telnr','$rooms_id',0,'127.0.0.1',NULL,'0000-00-00 00:00:00','0000-00-00 00:00:00',NULL,NULL,'$middlename',NULL,NULL,NULL,'$loc_telnr',0,0,'$title','$first_letters',0,'GET')";






$result2=mysql_query($sql2);

      }



// if not found passkey, display message "Wrong Confirmation code"

else

     {

echo "Wrong Confirmation code";

     }

// if successfully moved data from table"member" to table "users" displays message "Your account has been activated" and don't forget to delete confirmation code from table "temp_members_db"

if($result2)

{



echo "The account has been activated";



// Delete information of this user from table "temp_members_db" that has this passkey

$sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";

$result3=mysql_query($sql3);



}



}




}

elseif ($_POST['gender']=='deactivate')

{

echo "Deactivate Selected";

}

?>

Link to comment
Share on other sites

I checked with the code:

<?PHP

include('config.php');

 

$passkey=$_GET['passkey'];

 

echo "$passkey";

#$activate_status = 'unchecked';

#$deactivate_status = 'unchecked';

 

if ($_POST['gender']=='activate')

{

 

$tbl_name1="member";

$sql1="Select * from $tbl_name1 where loginname='$passkey'";

 

$result1=mysql_query($sql1);

 

// If successfully queried

if($result1)

    {

 

// Count how many row has this passkey

$count=mysql_num_rows($result1);

echo "$count";

// if found this passkey in our database, retrieve data from table "temp_members_db"

if($count==1)

      {

 

$rows=mysql_fetch_array($result1);

echo "$rows";

$firstname=$_POST['firstname'];

echo "$firstname";

----------------

But its shwoing some error I think:

Coz the output is :

 

maheshk1Array

 

maheshk is the passkey,1 is the output for count,Array(no idea)

 

 

Can you pls look at the code and help me with the solution

Link to comment
Share on other sites

I tried to troubleshoot and now I think you need to help me wiht few stuffs left.The Code is working.It is inserting half ata into the database...esp the cloumns which I am supplying as default in the code.

See This:

if($count==1)
       {

$rows=mysql_fetch_array($result1);
$firstname=$_POST['firstname'];
echo "$firstname";
$surname=$_POST['surname'];
echo "$surname";
$email=$_POST['email'];
$password=$_POST['password'];
$loginname=$_POST['loginname'];
$telnr=$_POST['telnr'];
$rooms_id=$_POST['rooms_id'];
$organisation_id=$_POST['organisation_id'];
$middlename=$_POST['middlename'];
$group_id=$_POST['group_id'];
$department_id=$_POST['department_id'];
$loc_telnr=$_POST['loc_telnr'];
$title=$_POST['title'];
$first_letters=$_POST['first_letters'];
echo "Hai";
$tbl_name2="users";
$sql2="INSERT INTO $tbl_name2(firstname,surname,email,password,is_admin,loginname,personeelsnummer,allowed_to_log_in,telnr,rooms_id,may_log_in,ip,session_key,last_contact,initial_contact,last_visited_page,organisation_id,middlename,group_id,department_id,building_id,loc_telnr,global_view,sla_level_id,title,first_letters,session_use_alerts,notes)
VALUES ('$firstname','$surname','$email','$password',0,'$loginname',NULL,NULL,'$telnr','$rooms_id',0,'127.0.0.1',NULL,'0000-00-00 00:00:00','0000-00-00 00:00:00',NULL,NULL,'$middlename',NULL,NULL,NULL,'$loc_telnr',0,0,'$title','$first_letters',0,'GET')";

 

The $firstname is not giving any value.But When I saw the database entry it is simpl adding the already inputted values like 0,127.0.0.1 etc..

Is the format correct?

Why $firstname isnt retrieving anything???

 

Pls Help

Link to comment
Share on other sites

hehe glad you tried trouble shooting yourself - its the bestway to learn,

 

anyway, so what are your problems as of right now? $firstname?

 

so your saying the insert.php is not picking up the firstname input?

 

echo out $_POST make sure its not anywhere else, make sure the input name is EXACLY the same as the _POST name.

 

EDIT: use Print_r($_POST); to view all the post variables.

Link to comment
Share on other sites

I got the Solution....I think I am very careless about the right Programming....

Here lies the Culprit:

.............

----------

$firstname=$rows['firstname'];

$surname=$rows['surname'];

$email=$rows['email'];

$password=$rows['password'];

$loginname=$rows['loginname'];

$telnr=$rows['telnr'];

 

 

And all I was using $_POST['row']----------------

 

Anyway Now everything seems to work.

 

Thanks for dedicating TIme to solve my DIfficulty.I learnt a lot from Yu.

 

See Yu Bye..

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.