PHP: If-Statement & Form
up vote
0
down vote
favorite
my code is ...
<?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 a n1 day");
}
?>
somehow, I always get <div class="alert alert-danger">Bitte fülle alle Felder aus.</div>
, even when the forms aren't empty.
why?
here's my 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, but I don't think that's the problem.
and the code looks fine too.
php forms
|
show 3 more comments
up vote
0
down vote
favorite
my code is ...
<?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 a n1 day");
}
?>
somehow, I always get <div class="alert alert-danger">Bitte fülle alle Felder aus.</div>
, even when the forms aren't empty.
why?
here's my 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, but I don't think that's the problem.
and the code looks fine too.
php forms
3
Where are your variables being set? Can you provide your form markup too?
– Jon Stirling
May 14 '15 at 21:34
First check that you are actually getting values back from the form, you can use: print_r($_REQUEST);die; . Than show some more code where you are actually assigning this from $_POST (or $_GET) into those variables. you're not using extract, right?
– Mahakala
May 14 '15 at 21:39
1
You realize that the name doesn't magically turn into$username
, but$_POST['username']
– adeneo
May 14 '15 at 21:41
edited the topic.
– Underbytex
May 14 '15 at 21:43
1
Please, stop usingmysql_*
functions. They are no longer maintained and are officially deprecated. Learn about prepared statements instead, and consider using PDO, it's not as hard as you think.
– Jay Blanchard
May 14 '15 at 21:46
|
show 3 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
my code is ...
<?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 a n1 day");
}
?>
somehow, I always get <div class="alert alert-danger">Bitte fülle alle Felder aus.</div>
, even when the forms aren't empty.
why?
here's my 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, but I don't think that's the problem.
and the code looks fine too.
php forms
my code is ...
<?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 a n1 day");
}
?>
somehow, I always get <div class="alert alert-danger">Bitte fülle alle Felder aus.</div>
, even when the forms aren't empty.
why?
here's my 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, but I don't think that's the problem.
and the code looks fine too.
php forms
php forms
edited Nov 11 at 16:16
Cœur
17.2k9102141
17.2k9102141
asked May 14 '15 at 21:32
Underbytex
99115
99115
3
Where are your variables being set? Can you provide your form markup too?
– Jon Stirling
May 14 '15 at 21:34
First check that you are actually getting values back from the form, you can use: print_r($_REQUEST);die; . Than show some more code where you are actually assigning this from $_POST (or $_GET) into those variables. you're not using extract, right?
– Mahakala
May 14 '15 at 21:39
1
You realize that the name doesn't magically turn into$username
, but$_POST['username']
– adeneo
May 14 '15 at 21:41
edited the topic.
– Underbytex
May 14 '15 at 21:43
1
Please, stop usingmysql_*
functions. They are no longer maintained and are officially deprecated. Learn about prepared statements instead, and consider using PDO, it's not as hard as you think.
– Jay Blanchard
May 14 '15 at 21:46
|
show 3 more comments
3
Where are your variables being set? Can you provide your form markup too?
– Jon Stirling
May 14 '15 at 21:34
First check that you are actually getting values back from the form, you can use: print_r($_REQUEST);die; . Than show some more code where you are actually assigning this from $_POST (or $_GET) into those variables. you're not using extract, right?
– Mahakala
May 14 '15 at 21:39
1
You realize that the name doesn't magically turn into$username
, but$_POST['username']
– adeneo
May 14 '15 at 21:41
edited the topic.
– Underbytex
May 14 '15 at 21:43
1
Please, stop usingmysql_*
functions. They are no longer maintained and are officially deprecated. Learn about prepared statements instead, and consider using PDO, it's not as hard as you think.
– Jay Blanchard
May 14 '15 at 21:46
3
3
Where are your variables being set? Can you provide your form markup too?
– Jon Stirling
May 14 '15 at 21:34
Where are your variables being set? Can you provide your form markup too?
– Jon Stirling
May 14 '15 at 21:34
First check that you are actually getting values back from the form, you can use: print_r($_REQUEST);die; . Than show some more code where you are actually assigning this from $_POST (or $_GET) into those variables. you're not using extract, right?
– Mahakala
May 14 '15 at 21:39
First check that you are actually getting values back from the form, you can use: print_r($_REQUEST);die; . Than show some more code where you are actually assigning this from $_POST (or $_GET) into those variables. you're not using extract, right?
– Mahakala
May 14 '15 at 21:39
1
1
You realize that the name doesn't magically turn into
$username
, but $_POST['username']
– adeneo
May 14 '15 at 21:41
You realize that the name doesn't magically turn into
$username
, but $_POST['username']
– adeneo
May 14 '15 at 21:41
edited the topic.
– Underbytex
May 14 '15 at 21:43
edited the topic.
– Underbytex
May 14 '15 at 21:43
1
1
Please, stop using
mysql_*
functions. They are no longer maintained and are officially deprecated. Learn about prepared statements instead, and consider using PDO, it's not as hard as you think.– Jay Blanchard
May 14 '15 at 21:46
Please, stop using
mysql_*
functions. They are no longer maintained and are officially deprecated. Learn about prepared statements instead, and consider using PDO, it's not as hard as you think.– Jay Blanchard
May 14 '15 at 21:46
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
If you add the error logging
error_reporting(E_ALL);
ini_set('display_errors','On');
you will see this:
Deprecated:
mysql_real_escape_string()
: The mysql extension is
deprecated and will be removed in the future: use mysqli or PDO
instead in .../public_html/index.php on line 38
Warning:
mysql_real_escape_string()
: Access denied for user 'www-data'@'localhost' (using password: NO) in
.../public_html/index.php on line 38
mysql_real_escape_string
requires you to connect to the database first. Also indeed this function is deprecated.
You can start with deleting mysql_real_escape_string
from the code to see that it works.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
If you add the error logging
error_reporting(E_ALL);
ini_set('display_errors','On');
you will see this:
Deprecated:
mysql_real_escape_string()
: The mysql extension is
deprecated and will be removed in the future: use mysqli or PDO
instead in .../public_html/index.php on line 38
Warning:
mysql_real_escape_string()
: Access denied for user 'www-data'@'localhost' (using password: NO) in
.../public_html/index.php on line 38
mysql_real_escape_string
requires you to connect to the database first. Also indeed this function is deprecated.
You can start with deleting mysql_real_escape_string
from the code to see that it works.
add a comment |
up vote
0
down vote
accepted
If you add the error logging
error_reporting(E_ALL);
ini_set('display_errors','On');
you will see this:
Deprecated:
mysql_real_escape_string()
: The mysql extension is
deprecated and will be removed in the future: use mysqli or PDO
instead in .../public_html/index.php on line 38
Warning:
mysql_real_escape_string()
: Access denied for user 'www-data'@'localhost' (using password: NO) in
.../public_html/index.php on line 38
mysql_real_escape_string
requires you to connect to the database first. Also indeed this function is deprecated.
You can start with deleting mysql_real_escape_string
from the code to see that it works.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
If you add the error logging
error_reporting(E_ALL);
ini_set('display_errors','On');
you will see this:
Deprecated:
mysql_real_escape_string()
: The mysql extension is
deprecated and will be removed in the future: use mysqli or PDO
instead in .../public_html/index.php on line 38
Warning:
mysql_real_escape_string()
: Access denied for user 'www-data'@'localhost' (using password: NO) in
.../public_html/index.php on line 38
mysql_real_escape_string
requires you to connect to the database first. Also indeed this function is deprecated.
You can start with deleting mysql_real_escape_string
from the code to see that it works.
If you add the error logging
error_reporting(E_ALL);
ini_set('display_errors','On');
you will see this:
Deprecated:
mysql_real_escape_string()
: The mysql extension is
deprecated and will be removed in the future: use mysqli or PDO
instead in .../public_html/index.php on line 38
Warning:
mysql_real_escape_string()
: Access denied for user 'www-data'@'localhost' (using password: NO) in
.../public_html/index.php on line 38
mysql_real_escape_string
requires you to connect to the database first. Also indeed this function is deprecated.
You can start with deleting mysql_real_escape_string
from the code to see that it works.
edited May 14 '15 at 22:21
Ferrrmolina
2,10321838
2,10321838
answered May 14 '15 at 21:53
Axalix
2,34911130
2,34911130
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30247727%2fphp-if-statement-form%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
Where are your variables being set? Can you provide your form markup too?
– Jon Stirling
May 14 '15 at 21:34
First check that you are actually getting values back from the form, you can use: print_r($_REQUEST);die; . Than show some more code where you are actually assigning this from $_POST (or $_GET) into those variables. you're not using extract, right?
– Mahakala
May 14 '15 at 21:39
1
You realize that the name doesn't magically turn into
$username
, but$_POST['username']
– adeneo
May 14 '15 at 21:41
edited the topic.
– Underbytex
May 14 '15 at 21:43
1
Please, stop using
mysql_*
functions. They are no longer maintained and are officially deprecated. Learn about prepared statements instead, and consider using PDO, it's not as hard as you think.– Jay Blanchard
May 14 '15 at 21:46