I'm working on a register function. over complex for a poor noob like me. What i want to do is register users who are above or below specified age range in a different db than everyone else. log their ip so they can't re register very easily. anyway when i try to register someone with an age that should move them into the other db and log thier ip it doesnt. does anyone know why this wont work. this should check if your age is equal to 24 check that your birthday is plausible then register you into the good db if it works and reroute you to the member page. if ($age == 24 ) { if($month > $date_month) { if($day >= $date_day) { $_SESSION['valid_user'] = $email; header( 'location:http://127.0.0.1/member.php' ); throw new Exception(register($email, $passwd, $fname, $lname)); } the registering code is date_default_timezone_set('UTC'); $year=$_POST['year']; $month= $_POST['month']; $day=$_POST['day']; $age=$_POST['age']; $date_year= date(Y); $Date_day= date(j); $date_month= date(n); $user_age= $date_year-$year; $email=$_POST['email']; $fname=$_POST['firstname']; $lname=$_POST['lastname']; $passwd=$_POST['passwd']; $passwd2=$_POST['passwd2']; $v_ip = $_SERVER['REMOTE_ADDR']; $conn = db_connect(); $result = $conn->query("select * from old where ip='".$v_ip."' "); //start a session //start the try //check email, password ect session_start(); try { if (!filled_out($_POST)) { throw new Exception('You have not filled the form out properly, please go back and try again. '); } if (!valid_email($email)) { throw new Exception('That is not a valid email address. Please go back and try again.'); } if ($passwd != $passwd2) { throw new Exception('The passwords you entered do not match, please go back and try again.'); } if ((strlen($passwd) < 6) || (strlen($passwd) > 16)) { throw new Exception('Your password must be between 6 and 16 characters Please go back and try again.'); } if ($user_age != $age) { throw new Exception ('Your age does not match your birthday.'); } if ($age == 24 ) { if($month > $date_month) { if($day >= $date_day) { $_SESSION['valid_user'] = $email; //header( 'location:http://127.0.0.1/member.php' ); echo"24"; throw new Exception(register($email, $passwd, $fname, $lname)); } } else { header( 'location:http://127.0.0.1/login.php' ); throw new Exception(old($email)); } } if ($age == 14 ) { if($month <= $date_month) { if($day <= $date_day) { $_SESSION['valid_user'] = $email; //header( 'location:http://127.0.0.1/member.php' ); echo"14"; throw new Exception(register($email, $passwd, $fname, $lname)); } } else { header( 'location:http://127.0.0.1/login.php' ); throw new Exception(old($email)); } } if ($age < 14 || $age > 24 ) { header( 'location:http://127.0.0.1/login.php' ); throw new Exception(old($email)); } if ($result->num_rows>0) { header( 'location:http://127.0.0.1/login.php' ); echo"fail4"; throw new exception (old($email)); } register($email, $passwd, $fname, $lname); $_SESSION['valid_user'] = $email; echo"$age"; echo"fail"; //header( 'location:http://127.0.0.1/member.php' ); do_html_header('Registration successful'); do_html_url('member.php', 'Go to members page'); do_html_footer(); } catch (Exception $e) { do_html_header('Problem:'); echo $e->getMessage(); do_html_footer(); exit; } the old function moves the registering person to the bad db, register function to the good db. Anyone have any ideas on fixing this problem. or maybe i should just rewrite it. if so any ideas on how to aproach it? thanks for any help
this is poor scripting.. dont use throw exceptions regularly, there will be some major effect depending on the server version. there's condition statement.. and what your asking is a bit odd. correct me if im wrong, are you categorizing ages by DATABASE?
I agree with bartolay13, this is conceptually flawed. All users should go in the same database table, regardless of their status or disposition. Then you just have fields that describe any attributes that should affect their ability to use the site. Then you can have a separate table for banned IP addresses. As it is, your approach is too convoluted to be worth spending time working out the details.
Alright is it conceptually flawed within using a try method or generally? can i possibly log them into different tables? Sorry i meant different tables not databases earlier. But could i possibly work this into a switch or perhaps an if and ifelse? I think what i most need to know is , is there anyway to have an if else statement where the results are exceptions? What i hoped to do was divide the the banned from the non banned into to easily reffernced tables. Thanks for your time. really.
actually you can divide the banned user to the not banned users... just simple if else can do it well i suggest why not putting all you users into one table and set one column for boolean data type if the user is banned or not.
i considered it but it would be nice if i could query the table with valid users first then low priority search the second if nothing turned up. would speed things up for valid users. or atleast that what i was thinking. But really it s no biggy i fugured it out. You guys were right what i needed was better logic. i tought it out and what i came up with that worked was a second else for the month section to handle that particular exception. Thanks for your help, i'm really glad to c this working=)
if it's only about querying valid users first, and then moving to non-valid ones, then all you need to do is set a table field which is 1 if user is 24, and 0 if not Then in your query you can do: "select * from table where age_field='1'" That will select only people with age 24 Using 2 completely different databases will create a lot of problem in future.