tuxbuddy Posted April 10, 2008 Share Posted April 10, 2008 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>              <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='' Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 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. Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 10, 2008 Author Share Posted April 10, 2008 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. Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 10, 2008 Author Share Posted April 10, 2008 More Clearly,Can you plis Browse through http://www.phpeasystep.com/phptu/24.html Its same process I am adopting...Exactly similar Concept Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 10, 2008 Author Share Posted April 10, 2008 If you browse thru that.....In my Case only Passkey stuff is not working.... Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 ok i checked over your code. what is the URL the email is giving? Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 10, 2008 Author Share Posted April 10, 2008 His Comfirmation link Click on this link to activate the users' account http://10.14.2.36/petp/activation.php?passkey=prabhu from: your name <your email> Just like the same above.. I made little chanhe in the language..Thats it.. Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 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 Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 10, 2008 Author Share Posted April 10, 2008 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"; } ?> Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 10, 2008 Author Share Posted April 10, 2008 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 Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 10, 2008 Author Share Posted April 10, 2008 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 Quote Link to comment Share on other sites More sharing options...
uniflare Posted April 10, 2008 Share Posted April 10, 2008 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. Quote Link to comment Share on other sites More sharing options...
tuxbuddy Posted April 11, 2008 Author Share Posted April 11, 2008 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.. Quote Link to comment 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.