i'm working in php , json @ api mobile application. tried write registration module, part of conditional statements don't work expected.
if statement 1 :
if(!isset($_get['username']) || !isset($_get['password']) || !isset($_get['imei']) || !isset($_get['imie']) || !isset($_get['nazwisko']) || !isset($_get['email']) || !isset($_get['zgoda']) || !isset($_get['telefon']) || !isset($_get['zgoda2']) || !isset($_get['kraj'])); { $returning = array('error' => 'invalid query'); echo json_encode($returning); break; } it should give error, when there argument missing, giving error always.
my query :
username=konrad12&password=xxx&imei=000000000000000&nazwisko=potter&imie=ronald&email=xxx@xxx.pl&zgoda=1&telefon=000&zgoda2=1&kraj=poland
if statement 2 :
if(strlen($c) != 15 || !validemail($f) || strlen($g) != 1 || strlen($i) != 1 || wez_id_kraju($j) == 0) { $returning = array('error' => 'invalid query'); echo json_encode($returning); break; } it should give error, when var values incorrect, giving error always.
my variables :
$z = mysql_real_escape_string($_get['username']); $b = mysql_real_escape_string($_get['password']); $c = mysql_real_escape_string($_get['imei']); $d = mysql_real_escape_string($_get['nazwisko']); $e = mysql_real_escape_string($_get['imie']); $f = mysql_real_escape_string($_get['email']); $g = mysql_real_escape_string($_get['zgoda']); $h = mysql_real_escape_string($_get['telefon']); $i = mysql_real_escape_string($_get['zgoda2']); $j = mysql_real_escape_string($_get['kraj']); if statement 3 :
if($g != 0 or 1 || $i != 0 or 1) { $returning = array('error' => 'invalid query'); echo json_encode($returning); break; } it should give error, when value of $g or $i isn't 1 or 0, giving error always.
please me, tried lot of things, can't find solution
@edit :
my valid email function :
function validemail($email) { $isvalid = true; $atindex = strrpos($email, "@"); if (is_bool($atindex) && !$atindex) { $isvalid = false; } else { $domain = substr($email, $atindex+1); $local = substr($email, 0, $atindex); $locallen = strlen($local); $domainlen = strlen($domain); if ($locallen < 1 || $locallen > 64) { // local part length exceeded $isvalid = false; } else if ($domainlen < 1 || $domainlen > 255) { // domain part length exceeded $isvalid = false; } else if ($local[0] == '.' || $local[$locallen-1] == '.') { // local part starts or ends '.' $isvalid = false; } else if (preg_match('/\\.\\./', $local)) { // local part has 2 consecutive dots $isvalid = false; } else if (!preg_match('/^[a-za-z0-9\\-\\.]+$/', $domain)) { // character not valid in domain part $isvalid = false; } else if (preg_match('/\\.\\./', $domain)) { // domain part has 2 consecutive dots $isvalid = false; } else if (!preg_match('/^(\\\\.|[a-za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local))) { // character not valid in local part unless // local part quoted if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local))) { $isvalid = false; } } if ($isvalid && !(checkdnsrr($domain,"mx") || ↪checkdnsrr($domain,"a"))) { // domain not found in dns $isvalid = false; } // add text ... mysql_connect(db_host, db_username, db_password); mysql_select_db(db_base); $q = "select * `system_domeny`"; $a = mysql_query($q); while($wynik = mysql_fetch_array($a)) { if($domena == $wynik[1]) $isvalid = false; } // ... } return $isvalid; }
remove semicolon after last bracket of if.
first statement ends
|| !isset($_get['kraj'])); i think second statement looks ok, issue email validation function or other function in last check.
the last statement should like
if(($g != 0 && $g != 1) || ($i != 0 && $i != 1))
Comments
Post a Comment