php - How to stop a return after a function processes (Prevent HTML from not loading) -


hello have function checks if registration details doesn't match in database, if does, return code.

but every time return code, html won't load because it's stopping loading. want html under php code, specific reason (i want errors display form, , not under).

this example of function:

function check_available($name, $password, $email) {     global $pdo;      $check_user = $pdo->prepare("select * users user_name = :username limit 1");     $check_user->execute( array(':username' => $name) );              $check_email = $pdo->prepare("select * users user_email = :email limit 1");     $check_email->execute( array(':email' => $email) );       $error = '';     if ($check_user->rowcount())     {         $error .= 'username exists!';         return handle_errors($error);     }     else if($check_email->rowcount() && !$check_user->rowcount())     {         $error .= 'email exists!';         return handle_errors($error);     }     else     {         return true;     } }      if (isset($_post['submit']))     {         $check_in = check_available($name, $password, $email);           if ($check_in == true)         {             echo 'created account sucessfully!';         }     } ?>   <html> <form action="register.php" method="post"> username: <input type="text" name="username"><br /> password: <input type="password" name="password"><br /> email: <input type="text" name="email"><br /> <input type="submit" name="submit"> </form> </html>  

after submiting, (with having username matches in database), html hide & error display.

how prevent this? there trick that?

there no point in hiding form.
quite contrary, form have shown let user enter name.

so, add error output form - that's need

edit
looks it's handle_errors() function blame.

function reg_has_errors($name, $password, $email) {     global $pdo;      $error = '';      $sql = "select 1 users user_name = ? limit 1";     $stm = $pdo->prepare($sql);     $stm->execute( array($name) );             if($stm->rowcount())     {         $error .= 'username exists!';     }      $sql = "select * users user_email = ? limit 1";     $stm = $pdo->prepare($sql);     $stm->execute( array($email) );             if($stm->rowcount())     {         $error .= 'email exists!';     }     return $error; }  $errors = ''; if (isset($_post['submit'])) {     $errors = reg_has_errors($name, $password, $email);      if (!$errors)     {         echo 'created account sucessfully!';     } } echo errors; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -