Jump to content

[SOLVED] :( My Script tries to register Twice can someone tell me why?[urgent :(]


Demonic

Recommended Posts

<?php
class register
{
function register()
{
	$Template = new TempSys;
	$x = 0;
	if(!isset($_POST['register']))
	{
		$Template->temp = "register.tpl";
		$Template->grab();
		return $Template->html;
	}
	else
	{
		if(!empty($_POST['username']) and !empty($_POST['email']) and !empty($_POST['pass2']) and !empty($_POST['pass1']))
		{
			if($_POST['pass1'] != $_POST['pass2'])
			{
				return "Password fields do not match.";
			}
			else
			{
				$username = w_input($_POST['username']);
				$already = mysql_query("SELECT `username` FROM `users` WHERE `username` = '".$username."'");
				if(mysql_num_rows($already) > 0)
				{
					return "Sorry, this account already exists.($x)";
				}
				else
				{
					$password = md5(w_input($_POST['pass1']));
					$email = w_input($_POST['email']);
					$val = substr(md5(rand(1000,30000)),0,10);			
						if(mysql_query("INSERT INTO `users` (`username`,`password`,`email`,`key`)
							VALUES('".$username."','".$password."','".$email."','".$val."')"))
							{
								validation($email,$username,$_POST['pass1'],$val);
								return "You have successfully been registered, please validated your account by checking your email.";
							}
							else
							{
								return "There was an sql error, contact the server administrator.";
							}
						$x += 1;
				}
			}
		}
		else
		{
			return "Sorry, you left a field blank.";
		}
	}
}
function run()
{
	switch($_GET['option'])
	{
		case "activate":
		//
		break;
		default:
			return $this->register();
		break;
	}
}
}
?>

 

It keeps echoing this user already exists, like its trying to register twice :(.  When I delete all the users from the db, i register all fine and dandy [well the user goes in the db], but at the same time it looks like its running the script a second time on the same post information, how come that is please i need this answer so  I can fix.

 

functions.php:

<?php
	function w_input($v)
	{
		$v = htmlspecialchars(htmlentities($v,ENT_QUOTES,'UTF-8'));
		return $v;
	}
	function validation($email,$name,$password,$key)
	{
		// To send HTML mail, the Content-type header must be set
		$headers  = 'MIME-Version: 1.0' . "\r\n";
		$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

		// Additional headers
		$headers .= 'To: '.$name.' <'.$email.'>' . "\r\n";
		$headers .= 'From: WeCodePython.info <wecodepy@wecodepython.info>' . "\r\n";
		$msg = "Hello $name,<br /><br />";
		$msg .= "Looks like you have registered at wecodepython.info, this requires you to validate your account.  <br />Your Account details are: <br />";
		$msg .= "Username: <b>$name</b><br />Password: <b>$password</b><br /><br />";
		$msg .= "Please follow this link to validate your account: <a href='http://wecodepython.info/index.php?action=register&option=validate&id=$key'>Here</a> (http://wecodepython.info/index.php?action=register&option=validate&id=$key)";
		$msg .= "<br /><br />Thanks again for registering, Regards WeCodePython.info";
		$msg = "-----------Security Output---------------<br />" . "IP: ".$_SERVER['REMOTE_ADDR']."<br />" . "From: " . $name . " <$email><br />" . "-----------Security EndPut---------------<br /><br />" . $msg;
		$subject = "WeCodePython.info - Validation Required";
		$email = w_input($email);
		mail($email,$subject,$msg,$headers);
	}
	function is_email($e)
	{

		if(preg_match("/.*@.*\.(com|net|us|org|info)/i",$e))
		{
			return true;
		}

	}
?>

Link to comment
Share on other sites

Nothing is more urgent than anyone else's work. Because you called it "urgent" and more important then anyone else's I won't even take a look at your code. YOUR WORK IS NOT URGENT OR MORE IMPORTANT.

 

>:( Read the forum guidelines.

Wow thats a great tip, thanks so very much.
Link to comment
Share on other sites

Nothing is more urgent than anyone else's work. Because you called it "urgent" and more important then anyone else's I won't even take a look at your code. YOUR WORK IS NOT URGENT OR MORE IMPORTANT.

 

>:( Read the forum guidelines.

Wow thats a great tip, thanks so very much.

 

It is a good tip. READ the FORUM GUIDELINES. Your stuck up attitude is not needed here. I need help too, but I don't go around calling it "urgent". Yes, maybe it is, but I restrict myself to the rules and try to help others, as others might need more help than me.

Link to comment
Share on other sites

Nothing is more urgent than anyone else's work. Because you called it "urgent" and more important then anyone else's I won't even take a look at your code. YOUR WORK IS NOT URGENT OR MORE IMPORTANT.

 

>:( Read the forum guidelines.

Wow thats a great tip, thanks so very much.

 

It is a good tip. READ the FORUM GUIDELINES. Your stuck up attitude is not needed here. I need help too, but I don't go around calling it "urgent". Yes, maybe it is, but I restrict myself to the rules and try to help others, as others might need more help than me.

 

Dude what are you talking about, I agreed to everything you said.  Your post was not needed.

 

Thanks rarebit, great help.

Link to comment
Share on other sites

Oh, sorry. You sound like you were sarcastic.

 

Anyway, I think you might need to change your code structure a bit.

 

<?php

if(mysql_query("INSERT INTO `users` (`username`,`password`,`email`,`key`)
							VALUES('".$username."','".$password."','".$email."','".$val."')"))

?>

 

You should instead do the mysql_query without the if and add or die();

 

This way the script stops running if the database isn't inserted properly.

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.