Demonic Posted September 16, 2007 Share Posted September 16, 2007 <?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; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/69517-solved-my-script-tries-to-register-twice-can-someone-tell-me-whyurgent/ Share on other sites More sharing options...
rarebit Posted September 16, 2007 Share Posted September 16, 2007 Where do you create and call the class register? Quote Link to comment https://forums.phpfreaks.com/topic/69517-solved-my-script-tries-to-register-twice-can-someone-tell-me-whyurgent/#findComment-349308 Share on other sites More sharing options...
Demonic Posted September 16, 2007 Author Share Posted September 16, 2007 I call it in classes\content.php, then thats called in classes\init.php [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/69517-solved-my-script-tries-to-register-twice-can-someone-tell-me-whyurgent/#findComment-349310 Share on other sites More sharing options...
TheFilmGod Posted September 16, 2007 Share Posted September 16, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69517-solved-my-script-tries-to-register-twice-can-someone-tell-me-whyurgent/#findComment-349311 Share on other sites More sharing options...
Demonic Posted September 16, 2007 Author Share Posted September 16, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69517-solved-my-script-tries-to-register-twice-can-someone-tell-me-whyurgent/#findComment-349312 Share on other sites More sharing options...
rarebit Posted September 16, 2007 Share Posted September 16, 2007 I don't know why I didn't notice it before, your register function is actually a constructor, so it's being called when it created and when run is called. Just renamed either the class or the function name register. You Are A Gent! lol Quote Link to comment https://forums.phpfreaks.com/topic/69517-solved-my-script-tries-to-register-twice-can-someone-tell-me-whyurgent/#findComment-349315 Share on other sites More sharing options...
TheFilmGod Posted September 16, 2007 Share Posted September 16, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69517-solved-my-script-tries-to-register-twice-can-someone-tell-me-whyurgent/#findComment-349318 Share on other sites More sharing options...
Demonic Posted September 16, 2007 Author Share Posted September 16, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69517-solved-my-script-tries-to-register-twice-can-someone-tell-me-whyurgent/#findComment-349320 Share on other sites More sharing options...
TheFilmGod Posted September 16, 2007 Share Posted September 16, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/69517-solved-my-script-tries-to-register-twice-can-someone-tell-me-whyurgent/#findComment-349321 Share on other sites More sharing options...
Demonic Posted September 16, 2007 Author Share Posted September 16, 2007 Lol, and naw its fine, I've done querys like that for the past year or so. Python got in the way so constructors threw me off. Quote Link to comment https://forums.phpfreaks.com/topic/69517-solved-my-script-tries-to-register-twice-can-someone-tell-me-whyurgent/#findComment-349324 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.