PHP: If-Statement & Form -
my code ...
<?php $username = mysql_real_escape_string($_post['username']); $password = mysql_real_escape_string($_post['password']); $passwordr = mysql_real_escape_string($_post['passwordr']); $email = mysql_real_escape_string($_post['email']); if(empty($username) || empty($password) || empty($passwordr) || empty($email)) { echo '<div class="alert alert-danger">bitte fülle alle felder aus.</div>'; } elseif(!preg_match('/^[a-za-z0-9-_^#]{4,15}$/', $username)) { echo '<div class="alert alert-danger">bitte gebe einen gültigen usernamen ein.<br />der username muss mindestens 4 und maximal 15 zeichen lang sein und darf nur folgende sonderzeichen enthalten: -_^#</div>'; } elseif(!preg_match('/^[a-za-z0-9-_*^#?!.,;@€]{8,20}$/', $password)) { echo '<div class="alert alert-danger">bitte gebe ein gültiges passwort ein.<br />das passwort muss mindestens 8 und maximal 20 zeichen lang sein und darf nur folgende sonderzeichen enthalten: -_*^#?!.,;@€</div>'; } elseif($passwordr != $password) { echo '<div class="alert alert-danger">die passwörter stimmen nicht überein.</div>'; } elseif(!preg_match('/^[a-za-z0-9-_.]+@[a-za-z0-9-_.]+\.[a-za-z]{2,4}$/', $email)) { echo '<div class="alert alert-danger">bitte gebe eine gültige e-mail adresse ein.</div>'; } else { die("have n1 day"); } ?>
somehow, <div class="alert alert-danger">bitte fülle alle felder aus.</div>
, when forms aren't empty.
why?
here's form ...
<div class="row"> <form method="post"> <fieldset> <div class="col-lg-5"> <div id="username-group" class="form-group"> <label for="username">username</label> <input type="text" name="username" id="username" class="form-control" placeholder="username"> </div> <div id="password-group" class="form-group"> <label for="password">passwort</label> <input type="password" name="password" id="password" class="form-control" placeholder="passwort"> </div> <div id="passwordr-group" class="form-group"> <label for="passwordr">passwort wiederholen</label> <input type="password" name="passwordr" id="passwordr" class="form-control" placeholder="passwort wiederholen"> </div> <div id="email-group" class="form-group"> <label for="email">e-mail</label> <input type="email" name="email" id="email" class="form-control" placeholder="e-mail"> </div> <input type="submit" name="submit" id="submit" class="btn btn-default" value="registrieren"> </div> </fieldset> </form> </div>
i'm using bootstrap, don't think that's problem. , code looks fine too.
it looks post code; please add more details.
if add error logging
error_reporting(e_all); ini_set('display_errors','on');
you see this:
deprecated:
mysql_real_escape_string()
: mysql extension deprecated , removed in future: use mysqli or pdo instead in .../public_html/index.php on line 38warning:
mysql_real_escape_string()
: access denied user 'www-data'@'localhost' (using password: no) in .../public_html/index.php on line 38
mysql_real_escape_string
requires connect database first. indeed function deprecated.
you can start deleting mysql_real_escape_string
code see works.
Comments
Post a Comment