Hello there...
I've been trying to solve this for... I don't know how long now.. maybe someone can help me? I'be real happy...
U see, I've made a page where u can register a user... with all the code on the same page.. that is, if u register yourself, all the php that checks that the username isn't taken allready and so on, is in the same file as the registration form is... I want it that way, so when u write your e-mail or whatever the wrong way, the information about that pops up next to that same feild on the same page instead of popping up in a new page, making the user push some back button to re-enter the information...
and it works real nice...
The only problem is that when the user have registered him - or herself successfully, he's still on the same page. with the form and all... And he can't see if he has registered himself or not...
How can I change that so that some text comes up, saying something like
"Congratulations, u're now a registered user and u can log in"..or whatever...
u can check and try it out if u don't understand what I mean here...
http://www.flameline.com/login/register.php
try to write stuff like the e-mail and so on wrong and see if it works...
When u've written everything right, u'll see that nothing happens... that's what I wanna change...
hmm... I'll post my validation php and the form code (they are in the same file) here... I'm not sure if u need it or not... also, if u have time and so on, come with suggestions on improving the code...
<?php if($login = "newuser") { ?>
<?php
$username = $_POST["username"];
$password = $_POST["password"];
$password2 = $_POST["password2"];
$email = $_POST["email"];
$set = $_POST["set"];
function emailsyntax_is_valid($email) {
$to_work_out = explode("@", $email);
if (!isset($to_work_out[0])) return FALSE;
if (!isset($to_work_out[1])) return FALSE;
$pattern_local = '^([0-9a-z]*([-|_]?[0-9a-z]+)*)(([-|_]?)\.([-|_]?)[0-9a-z]*([-|_]?[0-9a-z]+)+)*([-|_]?)$';
$pattern_domain = '^([0-9a-z]+([-]?[0-9a-z]+)*)(([-]?)\.([-]?)[0-9a-z]*([-]?[0-9a-z]+)+)*\.[a-z]{2,4}$';
$match_local = eregi($pattern_local, $to_work_out[0]);
$match_domain = eregi($pattern_domain, $to_work_out[1]);
if ($match_local && $match_domain) {
return TRUE;
}
return FALSE;
}
if ($set=="set") {
$username_control = 1;
$username2_control = 1;
$username3_control = 1;
$password_control = 1;
$password2_control = 1;
$password3_control = 1;
$password4_control = 1;
$password5_control = 1;
$email_control = 1;
$email2_control = 1;
$main_control = 1;
$main_control2 = 0;
if($username == ""){
$empty_username = "Ooops! - You forgot to enter your username.";
$username_control = 0;
$main_control = 0;
}
elseif(strlen($username) < 4){
$empty_username = "Ooops! - Your username should be at least 4 letters long.";
$username2_control = 0;
$main_control = 0;
}
elseif(strlen($username) > 20){
$empty_username = "Ooops! - Your username can't be larger than 20 letters.";
$username3_control = 0;
$main_control = 0;
}
/*
elseif (!eregi("^[a-zA-Z0-9_\-]+$",$username)
$empty_username = 'Ooops! - You are only allowed to use these tecken:.';
}
*/
elseif($password == ""){
$empty_password = "Ooops! - You forgot to enter your password.";
$password_control = 0;
$main_control = 0;
}
elseif(strlen($password) < 4){
$empty_password = "Ooops! - Your password should be at least 4 letters long.";
$password4_control = 0;
$main_control = 0;
}
elseif(strlen($password) > 20){
$empty_password = "Ooops! - Your password can't be larger than 20 letters.";
$password5_control = 0;
$main_control = 0;
}
elseif($password2 == ""){
$empty_password2 = "Ooops! - You forgot to validate your password!";
$password2_control = 0;
$main_control = 0;
}
elseif($password2 !== "" && $password2 !== $password){
$empty_password2 = "Ooops! - The passwords don't match!";
$password3_control = "0";
$main_control = 0;
}
elseif($email == ""){
$empty_email = "Ooops! - You forgot to enter your e-mail.";
$email_control = 0;
$main_control = 0;
}
elseif(!emailsyntax_is_valid($email)) {
$empty_email = " Ooops! - Incorrect e-mail format.";
$email2_control = 0;
$main_control = 0;
}
elseif($main_control = 1){
$str = $username;
$str = strtolower($str);
require ('mysqlcon.php');
$result = mysql_query("SELECT * FROM reg_info", $starta);
while ($array = mysql_fetch_array($result)) {
if($str == $array["username"]) {
$empty_username = "Ooops! - The nickname you chose allready exists!";
$main_control2 = 1;
break;
mysql_close($starta);
}
}
}
}
if($main_control2 != 1 & $main_control = 1) {
require ('mysqlcon.php');
$sqlquery=mysql_query("INSERT INTO reg_info (username, password, email) VALUES ('$str', '$password','$email')");
mysql_close($starta);
}
?>
<form action="register.php" method="post" name="hej">
Username:<br>
<input type="text" name="username" size="15" class="inputSidebar" value="<?php if($username_control != 0){ echo $_POST['username'];} elseif(username2_control !=0){ echo $_POST['username'];} elseif(username3_control !=0){ echo $_POST['username'];}else{ echo ''; } ?>"> <?php echo $empty_username; ?> <br>
Password:<br>
<input type="password" name="password" size="15" class="inputSidebar" value="<?php if($password_control != 0){ echo $_POST['password'];} elseif($password4_control !=0){ echo $_POST['password'];}elseif($password5_control !=0){ echo $_POST['password'];}else{ echo ''; } ?>"> <?php echo $empty_password; ?><br>
Verify Password:<br>
<input type="password" name="password2" size="15" class="inputSidebar" value="<?php if($password2_control != 0 && $password_control != 0){ echo $_POST['password2'];} else{ echo ''; } ?>"> <?php echo $empty_password2; ?><br>
E-mail (In case you lose your password):<br>
<input type="text" name="email" size="15" class="inputSidebar" value="<?php echo $_POST['email']; ?>"><?php echo $empty_email; ?><br><br>
<input class="button" type="submit" name="submit" value="Create User">
<input type="hidden" name="set" value="set">
</form>
THanks in advance for all your help!!!