Jump to content

Blank screen after confirmation email


mikebyrne

Recommended Posts

I've got the following code to send the user a confirmation email upon registration but when the user clisck on the link, instead of getting a messege, I just get a blank screen?????

 

<?php
include('config.php');

// Passkey that got from link
$passkey=$_GET['passkey'];

$tbl_name1="temp_users";

// Retrieve data from table where row matchs this passkey
$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
$result1=mysql_query($sql1);

// If successfully queried
if($result1){

// Count how many row has this passkey
$count=mysql_num_rows($result1);

// if found the passkey in the database, retrieve data from table "temp_users"
if($count==1){

$rows=mysql_fetch_array($result1);
$name=$_POST['name'];
$address=$_POST['address'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$address3=$_POST['address3'];
$address4=$_POST['address4'];
$county=$_POST['county'];
$zip=$_POST['zip'];
$telephone=$_POST['telephone'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];

$tbl_name2="users";

// Insert data that retrieves from "temp_users" into table "users"
$sql2="INSERT INTO $tbl_name2(name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password',)";
$result2=mysql_query($sql2);
}

// if not found passkey, display message "Wrong Confirmation code"
else {
echo "Wrong Confirmation code";
}

// if successfully moved data from table"temp_users" 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 "Your account has been activated";

// Delete information of this user from table "temp_users" that has this passkey
$sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";
$result3=mysql_query($sql3);

}

}
?> 

Link to comment
https://forums.phpfreaks.com/topic/79018-blank-screen-after-confirmation-email/
Share on other sites

Its pretty hard to tell what your code is doing because of the distinct lack of indentation, but I can tell you now your $sql2 query looks malformed.

 

Try changing it to...

 

$sql2="INSERT INTO $tbl_name2 (name, address, address1, address2, address3, address4, county, zip, telephone, email, username, `password`) VALUES ('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password',)";

I just had this way working last week but with less fields etc. I'll definatly look at you idea once I get this test up and running

 

I've changed two lines in the config.php to

 

$sql2="INSERT INTO $tbl_name2 (name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password) VALUES ('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password',)";
$result=mysql_query($sql2) or die(mysql_error());

 

And I'm now getting the error:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1

If I'm not mistaken, password is a MySQL reserved keyword/function. Always use backticks (`) on table names and field names, single quote (') on values. That way, MySQL will recognize it as a field name, and not a keyword/function.

 

<?php
$sql2="INSERT INTO `$tbl_name2` (`name`, `address`, `address1`, `address2`, `address3`, `address4`, `county`, `zip`, `telephone`, `email`, `username`, `password`) VALUES ('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password',)";
$result=mysql_query($sql2) or die(mysql_error());

 

PhREEEk

I've fixed it to

$sql2="INSERT INTO `$tbl_name2` (`name`, `address`, `address1`, `address2`, `address3`, `address4`, `county`, `zip`, `telephone`, `email`, `username`, `password`) VALUES ('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')";
$result=mysql_query($sql2) or die(mysql_error());

 

But getting a blank screen after I click on the email link 

<?php
include('config.php');

// table name
$tbl_name=temp_users;

// Random confirmation code
$confirm_code=md5(uniqid(rand()));

// values sent from form
$name=$_POST['name'];
$address=$_POST['address'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$address3=$_POST['address3'];
$address4=$_POST['address4'];
$county=$_POST['county'];
$zip=$_POST['zip'];
$telephone=$_POST['telephone'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];


// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code, name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$confirm_code', '$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')";
$result=mysql_query($sql)or die(mysql_error());

// if suceesfully inserted data into database, send confirmation link to email
if($result){

// ---------------- SEND MAIL FORM ----------------

// send e-mail to ...
$to=$email;

// Your subject
$subject="Your confirmation link here";

// From
$header="from: postmaster@localhost <postmaster@localhost>";

// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://localhost/confirm.php?passkey=$confirm_code";

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

}

// if not found
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}

?>

 

This all seems to work fine its the confirm.php I'm having trouble with

My confirm.php looks like this but I'm still getting the blank screen

 

<?php
include('config.php');

// Passkey that got from link
$passkey=$_GET['passkey'];

$tbl_name="temp_users";

// Retrieve data from table where row matchs this passkey
$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
$result1=mysql_query($sql1);

// If successfully queried
if($result1){

// Count how many row has this passkey
$count=mysql_num_rows($result1);

// if found the passkey in the database, retrieve data from table "temp_users"
if($count==1){

$rows=mysql_fetch_array($result1);
$name=$_POST['name'];
$address=$_POST['address'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$address3=$_POST['address3'];
$address4=$_POST['address4'];
$county=$_POST['county'];
$zip=$_POST['zip'];
$telephone=$_POST['telephone'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];

$tbl_name2="users";

// Insert data that retrieves from "temp_users" into table "users"

$sql2="INSERT INTO `$tbl_name2` (`name`, `address`, `address1`, `address2`, `address3`, `address4`, `county`, `zip`, `telephone`, `email`, `username`, `password`) VALUES ('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')";
$result=mysql_query($sql2) or die(mysql_error());
}

// if not found passkey, display message "Wrong Confirmation code"
else {
echo "Wrong Confirmation code";
}

// if successfully moved data from table"temp_users" 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 "Your account has been activated";

// Delete information of this user from table "temp_users" that has this passkey
$sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";
$result3=mysql_query($sql3);

}

}
?> 

Try this some modifications I did, if($count > 0) you had kept ==1, if you are sure query will return only 1 result then keep urs

 

<?php
include('config.php');

// Passkey that got from link
## added here
if (isset($_GET['passkey']))
{
$passkey=$_GET['passkey'];
} 
else
{
echo "Error here :: PASSKEY NOT FOUND ";
}

## table name
$tbl_name="temp_users";

// Retrieve data from table where row matchs this passkey
$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
$result1=mysql_query($sql1) or die(mysql_error());

// If successfully queried
if($result1)
{
// Count how many row has this passkey
$count=mysql_num_rows($result1);
## again addeded here
echo "I HAVE REACHED HERE, RESULT WAS SUCCESSFUL AND TOTAL ROWS  ".$count;
##
// if found the passkey in the database, retrieve data from table "temp_users"
## ARE YOU SURE YOU ARE GETTING ONLY ONE RESULTS 
if($count > 0) // i changed here.........
{
$rows=mysql_fetch_array($result1);
$name=$_POST['name'];
$address=$_POST['address'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$address3=$_POST['address3'];
$address4=$_POST['address4'];
$county=$_POST['county'];
$zip=$_POST['zip'];
$telephone=$_POST['telephone'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];

$tbl_name2="users";

// Insert data that retrieves from "temp_users" into table "users"

$sql2="INSERT INTO `$tbl_name2` (`name`, `address`, `address1`, `address2`, `address3`, `address4`, `county`, `zip`, `telephone`, `email`, `username`, `password`) VALUES ('$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')";
$result2=mysql_query($sql2) or die(mysql_error());
}

// if not found passkey, display message "Wrong Confirmation code"
else {
echo "Wrong Confirmation code";
	 }

// if successfully moved data from table"temp_users" 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 "Your account has been activated";
// Delete information of this user from table "temp_users" that has this passkey
$sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";
$result3=mysql_query($sql3) or die(mysql_error());

}

}
?> 

Archived

This topic is now archived and is closed to further replies.

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