mysql - php variable isn't visible inside of IF statement -
i have 2 steps sign form. first step i'm picking email , username , second step want pick first name , lastname , add db. problem variables i've got first post
form, $bridge_username
exact, not available in if statement below (the first 1 bottom). thing visible anywhere else, not inside particular if
statement. i've tried everything, including sessions. can see variable still there (using vardump
or echo
ing out), everywhere not need it... i'll happy hear advises.
$bridge_email = $_post['email']; $bridge_username = $_post['username']; $bridge_pass = $_post['password']; $bridge_pass_conf = $_post['passconf']; $bridge_terms = $_post['terms']; $bridge_pass_counted = strlen($bridge_pass); $bridge_username_counted = strlen($bridge_username); if (isset ($_post['email']) , isset ($_post['password']) , isset ($_post['passconf']) , isset ($_post['username'])) { if ($bridge_email != '' , $bridge_pass != '' , $bridge_pass_conf != '' , $bridge_username != '' , $bridge_terms != '') { if ($bridge_pass == $bridge_pass_conf) { if ($bridge_pass_counted >= 33 or $bridge_pass_counted <= 5) { } else { if ($bridge_username_counted >= 65 or $bridge_username_counted <= 3) { } else { if (is_numeric(substr($bridge_username, 0, 1))) { } else { //check if username or email exist $checkreguser = $mysqli->query("select username `engine_users` username = '$bridge_username' or email = '$bridge_email' limit 0, 1 "); $checkreguser = $checkreguser->fetch_assoc(); if ($checkreguser == '') { //creating new user $mysqli->query("insert `users` (`id`, `username`, `password`, `email`, `fname`, `lname`, `company`, `address`, `city`, `state`, `zip`, `country`, `currency`, `phone`, `vat`, `userlevel`, `created`, `notes`, `lastlogin`, `lastip`, `active`) values\n" . "(null, '$bridge_username', '1411678a0b9e25ee2f7c8b2f7ac92b6a74b3f9c5', '$bridge_email', '', '', null, '', '', '', '', '', '', '', null, 5, '2011-05-01 18:10:14', '', '2013-04-19 22:25:11', '127.0.0.1', 'y')"); }}}}}}} $bridge_fname = $_post['1_1_3']; $bridge_lname = $_post['1_1_4']; if (isset ($_post['1_1_3']) , isset ($_post['1_1_4'])) { $mysqli->query("update `users` set `fname` = '$bridge_fname',`lname` = '$bridge_lname' `users`.`username` = '$bridge_username'"); }
i fixed code bit make example, main issue how build query string
..." username = '$bridge_username' "
this result in string see it
(it debug print queries, before executing them) have change to:
." username = '".$bridge_username."' "
and variable replaced value.
also added checks post values, don't warnings if not set.
$bridge_email = (isset($_post['email']) ? $_post['email'] : null); $bridge_username = (isset($_post['username']) ? $_post['username'] : null); $bridge_pass = (isset($_post['password']) ? $_post['password'] : null); $bridge_pass_conf = (isset($_post['passconf']) ? $_post['passconf'] : null); $bridge_terms = (isset($_post['terms']) ? $_post['terms'] : null); //$bridge_pass_counted = strlen($bridge_pass); //$bridge_username_counted = strlen($bridge_username); //return , stay chained ifs if (!$bridge_email || !$bridge_username || !$bridge_pass || !$bridge_pass_conf) { return; } if ($bridge_pass != $bridge_pass_conf) { return; } if ($bridge_pass , strlen($bridge_pass) > 5 , strlen($bridge_pass) < 33) { return; } if ($bridge_username , strlen($bridge_username) > 5 , strlen($bridge_username) < 33) { return; } if (is_numeric(substr($bridge_username, 0, 1))) { return; } $result = $mysqli->query("select username `engine_users` username = '" . $bridge_username . "' or email = '" . $bridge_email . "' limit 0, 1 "); $checkreguser = $result->fetch_assoc(); // returns associative array of strings or null if there no more rows //if ($checkreguser == '') { if ($checkreguser === null) { //creating new user $mysqli->query("insert `users` (`id`, `username`, `password`, `email`, `fname`, `lname`, `company`, `address`, `city`, `state`, `zip`, `country`, `currency`, `phone`, `vat`, `userlevel`, `created`, `notes`, `lastlogin`, `lastip`, `active`) values\n" . "(null, '" . $bridge_username . "', '1411678a0b9e25ee2f7c8b2f7ac92b6a74b3f9c5', '" . $bridge_email . "', '', '', null, '', '', '', '', '', '', '', null, 5, '2011-05-01 18:10:14', '', '2013-04-19 22:25:11', '127.0.0.1', 'y')"); } $bridge_fname = (isset($_post['1_1_3']) ? $_post['1_1_3'] : null); $bridge_lname = (isset($_post['1_1_4']) ? $_post['1_1_4'] : null); if ($bridge_fname , $bridge_lname ) { $mysqli->query("update `users` set `fname` = '" . $bridge_fname . "',`lname` = '" . $bridge_lname . "' `users`.`username` = '" . $bridge_username . "'"); }
please examine if structure, returning makes code more readable.
Comments
Post a Comment