confirmation problem (pls help)

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
Slav2
Posts: 96
Joined: Tue Jan 11, 2011 7:46 am

confirmation problem (pls help)

Post by Slav2 »

ok first off ill put everything here:

ok this is my registernext.php

Code: Select all

<?php
include('confff.php');
//test to see if username is alfanumeric
$testname=$_POST['username'];
if(!preg_match('[^0-9a-zA-Z]', $username))
{
	//test for duplicate names
	$username = $_POST['username'];
	$username=strip_tags($username);
	$query="SELECT * FROM users WHERE username ='$username'";
	$result=mysql_query($query);
	$num=mysql_num_rows($result);

	if ($num == 0)
	{
		//test for duplicate emails
		$email = $_POST['email'];
		$email=strip_tags($email);
		$query2="SELECT * FROM users WHERE email ='$email'";
		$result2=mysql_query($query2);
		$num2=mysql_num_rows($result2);
		
		if($num2==0)
		{
			//if emails and passwords match up
			if(($_POST['pass']==$_POST['pass2']) && ($_POST['email']==$_POST['email2']))
			{
				//generate random confirmation code
				$confirmation_code=md5(uniqid(rand()));
				$passkey = $confirmation_code;
				
				$sql="INSERT INTO temp (code, username, email, password) VALUES ('$confirmation_code', '$testname', '$email', '$pass')";
				if (!mysql_query($sql,$con))
					{
						die('Error: ' . mysql_error());
						}
					if($sql)
					{
						$message="Your Confirmation link \r\n
Click on this link to activate your account \r\n
http://www.royalempires.com/confirmation.php?passkey=$confirmation_code";

							$sentmail=mail("$email",'Registration Confirmation',"$message" ,'From: admin@royalempires.com');
							header("Location:thankyou.html");
					}
					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 e-mail account";
				}
				else
				{
					echo "cannot send confirmation link to your e-mail adress";
				}
			}
			else
			{
				header("location:badmatch.html");                              
			}
		}
		else
		{
			header("Location:emailinuse.html");
		}
	}
	else
	{
		header("Location:nameinuse.html");
	}
}

?>
ok, it adds everything corectly into the temp table, but im not getting a confirmation message...
Thanks,

Slav2
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: confirmation problem (pls help)

Post by PaxBritannia »

Your mail program may not be installed/configured properly. To see if it is, try making a new php file and inserting this code. Remember to change the email adress (you can have the 'from' at a different address), and see if you receive it.

Code: Select all

<?php
$to = "someone@example.com";
$subject = "Test mail";
$message = "Hello! Your email server works!";
$from = "bob@example.com";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?> 
If you do receive it, then the error will be in the original script, else it will be in your server configuration.

One more thing, after you define your mail variable add this:

Code: Select all

$message = wordwrap($message, 70);
It word wraps line which are longer than 70 characters, which is needed for the mail() function to work properly.

Also personally, I don't think sending mail is such a good idea. The chances that it will be sent to junk, the usability issues, the inconvenience are a definite negative. The fact that confirmations through email is now considered annoying and pointless by the user is another.

Your game doesn't need an email. The only useful thing it could do would be to make sure there are no duplicate accounts. But with creating a new account at gmail/yahoo/hotmail so easy ( I have at least 60 accounts at free providers, and 20 accounts at private providers :D ( Don't worry, I don't spam :) )), even the usefulness of this is deteriorating.

The final decision is yours.

pax.
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: confirmation problem (pls help)

Post by hallsofvallhalla »

are you running this script localhost?
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: confirmation problem (pls help)

Post by PaxBritannia »

I believe it is in live production mode (though I can't tell you the url without Slav's permission).

pax.
User avatar
Slav2
Posts: 96
Joined: Tue Jan 11, 2011 7:46 am

Re: confirmation problem (pls help)

Post by Slav2 »

Pax thanks once again. Ill try this in the morning and tell u how it went. And ye, I'm using hostmonster. And ummm well I guess it's ok if the URL is posted on here. But like it's still in the super early stages.
Thanks,

Slav2
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: confirmation problem (pls help)

Post by PaxBritannia »

Ok, tell me how it goes. I'll post the url only if it's needed.

See you in the morning.

pax.
User avatar
Ravinos
Posts: 281
Joined: Tue Sep 15, 2009 4:14 pm

Re: confirmation problem (pls help)

Post by Ravinos »

I use a very similar confirmation system to Pax's for registering/retrieving forgotten passwords. I couldn't get it to work with my localhost no matter how much I tried but as soon as I uploaded it to my test site, it worked like a charm.....except for the 10-30 minute delay in people receiving emails. Use her example as a test platform to see if your host is configured right.
User avatar
Slav2
Posts: 96
Joined: Tue Jan 11, 2011 7:46 am

Re: confirmation problem (pls help)

Post by Slav2 »

wow thanks it works! i put it into my actual table: (and there is no delay at all)
and one thing i was wondering, what do i add to make diff parts of the $message appear on diff lines in the inbox of the email? like would i just add a </br> tag in the middle of the message sortof like this:

Hello! </br>Click on this link to activate your account: </br> ............???

Code: Select all

if($sql)
					{
						$to = "$email";
						$subject = "Confirmation";
						$message = "Hello! Click on this link to activate your account: http://www.royalempires.com/confirmation.php?passkey=$confirmation_code";
						$from = "admin@royalempires.com";
						$headers = "From: $from";
						$sentmail = mail($to,$subject,$message,$headers);
						echo "Mail Sent.";
					}
					else
					{
						echo "Not found your email in our database";
					}
but pax on the thing you helped me out with last time is now screwing up...and its also not inserting the password from the temp table into the users table.......i used to allways do this, but its not anymore. pic:

http://i820.photobucket.com/albums/zz12 ... lnmsdk.jpg

and its also not adding anything into the resources table at all.

here are the codes:

Code: Select all

<?php
include("confff.php");//check
 
//set variable
$passkey=$_GET['passkey'];
$sql1="SELECT * FROM temp WHERE code='$passkey'";
$result1=mysql_query($sql1);
 
//if sucessfully queried
if($result1)
{
 
	//how many rows have key
	$count=mysql_num_rows($result1);
   
	//if passkey in database, retrieve data
	if($count==1)
	{
		$rows=mysql_fetch_array($result1);
		$namex=$rows['username'];
		$emailx=$rows['email'];
		$passwordx=$rows['password'];
	   
		//takeoutspace
		$name=str_replace(' ','',$namex);
		$email=str_replace(' ','',$emailx);
		$password=str_replace(' ','',$passwordx);
	   
		//insert into users table
		$sql2="INSERT INTO users SET username='$name', points='5', mycities='1', email='$email', password='$password'";
		$result2=mysql_query($sql2);
		
		if ($result2)
		{
		   
			//starting values
			$myCityname = $name . '\'s city';
			
			$sql43="SELECT * FROM users WHERE username='$name'";
			
			$result10=mysql_query($sql43);
			$result99=mysql_fetch_array($result10);
			$userid = $result99['id'];
			
			$sql3="INSERT INTO resources SET userid='$userid', cityname='$myCityname', wood='200', stone='200', iron='200', food='150', people='10', gold='100', happiness='100', loyalty='100'";
			$result3=mysql_query($sql3);
			
			//remove from temp
			$sql5="DELETE FROM temp WHERE code='$passkey'";
			$result=mysql_query($sql5);
			
			header("location:confirmation2.html");
		}
		else
		{
			echo "wrong confirmation code";
		}
	}
}
	 
?>
like it goes to the confirmation2.php but doesnt add the password and doesnt add anything into the resources table.
Thanks,

Slav2
User avatar
PaxBritannia
Posts: 680
Joined: Sun Apr 18, 2010 1:54 pm

Re: confirmation problem (pls help)

Post by PaxBritannia »

For making parts of $message appear on different lines, try and use "/n". You can just insert it like this:

Code: Select all

$message = "/n Hello! /n /n Click on this link to activate your account: /n http://www.royalempires.com/confirmation.php?passkey=$confirmation_code";
As for the database issue, try and add

Code: Select all

$result=mysql_query($sql) or die ('Error A:' mysql_errno() . ": " . mysql_error());
For every one you add, make sure the error letter is unique, so no two errors have the same letter. (By the way, they don't have to be in order).

This will tell us where in the script is it not working and why. After doing that, post your script and any error messages you get. Hope we solve this soon.

pax.
User avatar
Slav2
Posts: 96
Joined: Tue Jan 11, 2011 7:46 am

Re: confirmation problem (pls help)

Post by Slav2 »

oh ok. and umm well im not sure exactly were to add it....i put it in one part, and right away it said that it was an unexpected t_string that error message. so i deleted it and tried it without it....and this is what came up:

Parse error: syntax error, unexpected T_VARIABLE in /home2/royalemp/public_html/confirmation.php on line 49

Code: Select all

<?php
include("confff.php");//check
 
//set variable
$passkey=$_GET['passkey'];
$sql1="SELECT * FROM temp WHERE code='$passkey'";
$result1=mysql_query($sql1);
 
//if sucessfully queried
if($result1)
{
 
	//how many rows have key
	$count=mysql_num_rows($result1);
   
	//if passkey in database, retrieve data
	if($count==1)
	{
		$rows=mysql_fetch_array($result1);
		$namex=$rows['username'];
		$emailx=$rows['email'];
		$passwordx=$rows['password'];
	   
		//takeoutspace
		$name=str_replace(' ','',$namex);
		$email=str_replace(' ','',$emailx);
		$password=str_replace(' ','',$passwordx);
	   
		//insert into users table
		$sql2="INSERT INTO users (username, points, mycities, email, password) VALUES ('$name', '5', '1', '$email', '$password')";
		$result2=mysql_query($sql2);
		
		if ($result2)
		{
		   
			//starting values
			$myCityname = $name . '\'s city';
			
			$sql43="SELECT * FROM users WHERE username='$name'";
			
			$result10=mysql_query($sql43);
			$result99=mysql_fetch_array($result10);
			$userid = $result99['id'];
			
			$sql3="INSERT INTO resources (userid, cityname, wood, stone, iron, food, people, gold, happiness=, loyalty) VALUES ('$userid', '$mycityname', '200', '200', '200', '150', '200', '100', '100')";
			$result3=mysql_query($sql3)
			
			//remove from temp
			$sql5="DELETE FROM temp WHERE code='$passkey'";
			$result=mysql_query($sql5);
			
			header("location:confirmation2.html");
		}
		else
		{
			echo "wrong confirmation code";
		}
	}
}
	 
?>
and the worst part it that its now not even adding the password into the temp table? y isnt it?? it seems as it its all set up right......
Thanks,

Slav2
Post Reply

Return to “Advanced Help and Support”