Cant figure it out im trying to get if stament to checks with complex enterys in a form but it seams not to work...
Please help....
here is the function i cant get to work..
function usersyntax_is_valid($username) {
$to_work_out = $username;
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;
}
and here is the elseif check code
elseif(!usersyntax_is_valid($username)) {
$empty_username = "Ooops! - Incorrect username format.";
$username4_control = 0;
$main_control = 0;
}
and here is the complet code..
<?php
$username = $_POST["username"];
$set = $_POST["set"];
function usersyntax_is_valid($username) {
$to_work_out = $username;
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;
$username4_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(!usersyntax_is_valid($username)) {
$empty_username = "Ooops! - Incorrect username format.";
$username4_control = 0;
$main_control = 0;
}
elseif($main_control == 1){
$str = $username;
$str = strtolower($str);
require ('./management/mysqlcondbrr.php');
$result1 = mysql_query("SELECT username FROM reg_info where username='$str' LIMIT 1", $starta);
if (mysql_num_rows($result1)==0)
$empty_username = "Ooops! - The nickname you chose don't exists!";
$main_control2 = 1;
mysql_close($starta);
}
}
if($main_control2 != 1 && $main_control == 1) {
}
?>
<?PHP
function info() {
print "Please enter your usernamen in the blank field <br>
below to recive your password.<br>
Then press get password button to recive your<br>
password.<br>";
}function validuser() {
print "Thanks in some seconds you will recive a email <br>
with your password in it.<br>
If you get an error please read the error note <br>";
}
include ("./management/mysqlcondbrr.php");
if (!isset($_POST[username]))
{
}else{
$mysqlcon1 = "SELECT * FROM reg_info WHERE username='".$_POST[username]."'";
$result1 = mysql_query($mysqlcon1) or die("Error: " . mysql_error());
if (mysql_num_rows($result1) == '1') {
while ($row = mysql_fetch_array($result1)) {
$message = "Your password is ".$row['password']."";
$email = $row['email'];
$mail = mail($email, "Your Password", $message,"From: [email]administrator@flameline.com[/email]\r\n");
if ($mail) {
$sent_email = "Yes e-mail sent to you";
}
}
}else{
}
}
?>
<?php
if (!$username_control || !$username2_control || !$username3_control || !$username4_control || !$main_control2) {
info();
}else{
validuser();
}
?>
<br>
<form action="<?=$PHP_SELF?>" method="post" name="hej">
<b>Your Username Here:<br><br></b>
<input type="text" name="username" size="15" class="inputSidebar" val="<?php
if($username_control != 0){ echo $_POST['username'];}
elseif(username2_control !=0){ echo $_POST['username'];}
elseif(username3_control !=0){ echo $_POST['username'];}
elseif(username4_control !=0){ echo $_POST['username'];}
elseif(main_control2 != 0){ echo $_POST['username'];}
else{ echo ''; } ?>">
<?php echo $empty_username; ?>    
<input class="button" type="submit" name="submit" value="Get password">
<br>
                             
<?php echo $sent_email; ?>
<input type="hidden" name="set" value="set">
</form>