Jump to content

My IF not working in register Form and stop!


ManInBlack

Recommended Posts

Hi.

 

I have problem with my Register Form. The password check if password are over 16 of lengt it's just go over and send to the database and also the password check If the Password1 and password2 is not same. It do it also send to database and not stop. But it say it the password is not same and the password must be 6-16 charather.

 

Sorry my english.  :rtfm:

 

      if (!$_POST['password2'] == $_POST['password1']) $password2_fail = 'The password is not same.';
      if (strlen($_POST['password1']) > 16) $password1_fail = 'The password have to be middle 6-16 charather';

 

 

<?php
if( $_GET['gluggi'] == 'eydublad-athugun' ) {
      if (strlen($_POST['firstname']) < 2) $firstname_fail = 'Nafnið er of stutt';   
      if (strlen($_POST['email']) < 4) $email_fail = 'Netfang er ekki rétt';
      if (strlen($_POST['username']) < 3) $username_fail = 'Notendanafn þarf vera lengra enn 3 stafa';
      if (!$_POST['password2'] == $_POST['password1']) $password2_fail = 'Lykilorð eru ekki eins.';
      if (strlen($_POST['password1']) > 16) $password1_fail = 'Lykilorð verður vera milli 6 - 16 stafa orð';
      if (strlen($_POST['password1']) < 6) $password1_fail = 'Lykilorð verður vera milli 6 - 16 stafa orð';

   
else            
{
   $firstname = $_POST['firstname'];
            $email = $_POST['email'];
            $b_day = $_POST['b_day'];
            $b_month = $_POST['b_month'];
            $b_year = $_POST['b_year'];
            $username = $_POST['username'];
            $passw1 = $_POST['password1'];
            $pass2 = $_POST['password2'];
            $regtime_sec = '00';
            $regtime_year = '2009';
            $ip_number = '123.456.789.321';
            $regtime = date("Y-m-d H:i:s", mktime($klst,$minutur,$sekundur,$manudur,$dagur,$artal));
               $sql="INSERT INTO new_users (firstname,email,b_day,b_month,b_year,username,password,ip_number)
VALUES
('$firstname','$email','$b_day','$b_month','$b_year','$username','$passw1','$ip_number')";

if (!mysql_db_query('asdfga_ung',$sql,$sql_connect))die('villa kom upp: ' . mysql_error());
{
echo 'Go To Where?';

}} }
    
    
  





?>

For the first part, that is incorrect usage of the exclamation mark, when used it 'flips' the value of whatever it assigns to. You should be checking...

 

if ($_POST['password2'] != $_POST['password1']) $password2_fail = 'The password is not same.';

You should really use curly brackets on all if-else statements, regardless of if they are only one line, the logic of your code is not laid out the same way as it has been indented. The else block that actually does the inserting will be ran regardless of any of the errors except the last one, since the else only applies to that if statement. To fix that you will have to either a.) change all but the first if (of the error ifs, not the first one) to elseif, but then it will only flag the latestest error. b.) leave them all as if's but instead of putting the add code in an else block, check that all the error messages are NULL or blank strings.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.