I keep getting an error message of i use an else function in PHP -


this question has answer here:

here php block using:

$reg = @$_post['reg'];  $fn = ""; $ln = ""; $un = ""; $em = ""; $em2 = ""; $pswd = ""; $pswd2 = ""; $d = ""; $u_check = "";  $fn = strip_tags(@$_post['fname']); $ln = strip_tags(@$_post['lname']); $un = strip_tags(@$_post['username']); $em = strip_tags(@$_post['email']); $em2 = strip_tags(@$_post['email2']); $pswd = strip_tags(@$_post['password']); $pswd2 = strip_tags(@$_post['password2']); $d = date("y-m-d"); //year - month - day  if ($reg) {} if ($em==$em2){} $u_check = mysql_query("select username users username='$un'"); $check = mysql_num_rows ($u_check); if ($check == 0){} if ($fn&&$ln&&$un&&$em&&$em2&&$pswd&&$pswd2){} if ($pswd==$pswd2){} if (strlen($un)>25||strlen($fn)>25||strlen($ln)>25){ echo "the maximum amount of character 25! please try again"; } else { if (strlen($pswd)>30||strlen($pswd)<5){} echo "your password between 5 , 30 characters long!"; } else { $pswd = md5($pswd); $pswd2 = md5($pswd2); $query = mysql_query("insert users values (' ', '$un', '$fn', '$ln',    '$em','$pswd','$d','0')"); } 

and here 2 else statements:

else { if (strlen($pswd)>30||strlen($pswd)<5){} echo "your password between 5 , 30 characters long!"; } else { $pswd = md5($pswd); $pswd2 = md5($pswd2); $query = mysql_query("insert users values (' ', '$un', '$fn', '$ln',    '$em','$pswd','$d','0')"); } 

when have:

else { if (strlen($pswd)>30||strlen($pswd)<5){} echo "your password between 5 , 30 characters long!"; } 

i don't error message, when add:

else { $pswd = md5($pswd); $pswd2 = md5($pswd2); $query = mysql_query("insert users values (' ', '$un', '$fn', '$ln', '$em','$pswd','$d','0')"); } 

i error message when refresh:

parse error: syntax error, unexpected 'else' (t_else) in c:\xampp\htdocs\socially\index.php on line 39

i using youtube tutorial, , typed, didn't error message. here link: https://www.youtube.com/watch?v=egqvnmtnmdq&list=pla7f9875bd031dc16&index=36

this video done in 2013.

if me, appreciated.

your ifs wrong { opens control block , } closes it. example this:

if (strlen($pswd)>30||strlen($pswd)<5){} 

you doing nothing when password longer 30 characters or less 5. (also why limit passwords 30 characters?)

you echoing message regardless of condition:

echo "your password between 5 , 30 characters long!"; 

additional notes:

your control blocks should indented.

you should not put user data directly sql query. how injections occur. strip_tags nothing stop sql injection.

try:

<?php $reg = @$_post['reg']; $fn = ""; $ln = ""; $un = ""; $em = ""; $em2 = ""; $pswd = ""; $pswd2 = ""; $d = ""; $u_check = ""; $fn = strip_tags(@$_post['fname']);//dont use @, no need error supression, resolve errors. $ln = strip_tags(@$_post['lname']); $un = strip_tags(@$_post['username']); $em = strip_tags(@$_post['email']); $em2 = strip_tags(@$_post['email2']); $pswd = strip_tags(@$_post['password']); $pswd2 = strip_tags(@$_post['password2']); $d = date("y-m-d"); //year - month - day if ($reg) {}//does nothing if ($em==$em2){}//does nothing $u_check = mysql_query("select username users username='$un'"); $check = mysql_num_rows ($u_check); if ($check == 0){}//does nothing if ($fn&&$ln&&$un&&$em&&$em2&&$pswd&&$pswd2){}//does nothing if ($pswd==$pswd2){}//does nothing if (strlen($un)>25||strlen($fn)>25||strlen($ln)>25){     echo "the maximum amount of character 25! please try again"; } else {     if (strlen($pswd)>30||strlen($pswd)<5){         echo "your password between 5 , 30 characters long!";     } else {         $pswd = md5($pswd); //should upgrade hashing algorithm         $pswd2 = md5($pswd2);//not used         $query = mysql_query("insert users values (' ', '$un', '$fn', '$ln',            '$em','$pswd','$d','0')");//open sql injections     } } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -