Hallo Stackoverflow,PHP Leere Checks gibt immer Negative
ich wieder hier bin, und dieses Mal geht es um eine PHP-Funktion I erstellt. Ich versuche, einen Benutzer einen Pin setzen zu lassen, aber das Formular gibt immer den Fehler "Ein Feld ist leer" zurück. Es ist einfach seltsam. Alles funktioniert gut, sogar die anderen Fehlerüberprüfungen, aber das leere gibt nur ein Negativ zurück.
Das ist mein PHP
if(isset($_POST['pin-submit'])){
// Filter the Old PIN and IMPLODE it.
$pinold_1 = htmlentities($_POST['pinold-1']);
$pinold_2 = htmlentities($_POST['pinold-2']);
$pinold_3 = htmlentities($_POST['pinold-3']);
$pinold_4 = htmlentities($_POST['pinold-4']);
$array_old = array($pinold_1, $pinold_2, $pinold_3, $pinold_4);
$oldpin = implode("|", $array_old);
// Filter the New PIN and IMPLODE it.
$pinnew_1 = htmlentities($_POST['pinnew-1']);
$pinnew_2 = htmlentities($_POST['pinnew-2']);
$pinnew_3 = htmlentities($_POST['pinnew-3']);
$pinnew_4 = htmlentities($_POST['pinnew-4']);
$array_new = array($pinnew_1, $pinnew_2, $pinnew_3, $pinnew_4);
$newpin = implode("|", $array_new);
// Filter the New Repeated PIN and IMPLODE it
$pinnewrep_1 = htmlentities($_POST['pinnewrep-1']);
$pinnewrep_2 = htmlentities($_POST['pinnewrep-2']);
$pinnewrep_3 = htmlentities($_POST['pinnewrep-3']);
$pinnewrep_4 = htmlentities($_POST['pinnewrep-4']);
$array_newrep = array($pinnewrep_1, $pinnewrep_2, $pinnewrep_3, $pinnewrep_4);
$newreppin = implode("|", $array_newrep);
// Explode the User's actual PIN into pieces.
$array_actual = explode("|", $user['slp']);
$pinactual_1 = $array_actual[0];
$pinactual_2 = $array_actual[1];
$pinactual_3 = $array_actual[2];
$pinactual_4 = $array_actual[3];
// Check if Actual PIN is the Actual PIN.
if($user['slp'] !== $oldpin){
echo "<div class='alert alert-dismissible alert-danger'>";
echo "<strong>Hey {username}!</strong> Je actuele PIN klopt niet. Probeer het eventjes opnieuw.";
echo "</div>";
// Check if the New PIN is the Same as the Repeated New PIN.
}else if($newpin !== $newreppin){
echo "<div class='alert alert-dismissible alert-danger'>";
echo "<strong>Hey {username}!</strong> Je Nieuwe PIN komt niet overeen met de Herhaling van je nieuwe PIN.";
echo "</div>";
// Check if all Fields are filled in.
}else if (empty($pinold_1) || empty($pinold_2) || empty($pinold_3) || empty($pinold_4) ||
empty($pinnewrep_1) || empty($pinnewrep_2) || empty($pinnewrep_3) || empty($pinnewrep_4) ||
empty($pinnew_1) || empty($pinnew_2) || empty($pinnew_3) || empty($pinnew_4)){
echo "<div class='alert alert-dismissible alert-danger'>";
echo "<strong>Hey {username}!</strong> Je moet elk veld ingevuld hebben. Geen enkele mag leeg zijn!";
echo "</div>";
// Else Save the new PIN and show a Success message.
}else{
echo "<div class='alert alert-dismissible alert-success'>";
echo "<strong>Hey {username}!</strong> Je PIN is gewijzigd. Je kan hem direct gebruiken.";
echo "</div>";
}
}
Das ist mein HTML (Incl. Formular)
<form id="pinForm" name="pin" method="post" class="form-horizontal">
<span class="help-block"><strong>Je Second Layer PIN Wijzigen</strong><br>Pas hier jouw SLP aan. Vul eerst je actuele PIN in, en daarna de gewenste nieuwe.</span>
<label class="control-label" for="inputEmail">Actuele PIN</label>
<div class="form-group">
<div class="col-lg-10">
<input type="text" name="pinold-1" style="width:30px;" maxlength="1" size="1" id="pinform">
<input type="text" name="pinold-2" style="margin-left:8px; width:30px;" maxlength="1" size="1" id="pinform">
<input type="text" name="pinold-3" style="margin-left:8px; width:30px;" maxlength="1" size="1" id="pinform">
<input type="text" name="pinold-4" style="margin-left:8px; width:30px;" maxlength="1" size="1" id="pinform">
<span class="help-block" style="float:right;"><small>Je Second Layer PIN die je <strong>nu gebruikt</strong> bij je Magie Account.</small></span>
</div></div>
<label class="control-label" for="inputEmail">Nieuwe PIN</label>
<div class="form-group">
<div class="col-lg-10">
<input type="text" name="pinnew-1" style="width:30px;" maxlength="1" size="1" id="pinform">
<input type="text" name="pinnew-2" style="margin-left:8px; width:30px;" maxlength="1" size="1" id="pinform">
<input type="text" name="pinnew-3" style="margin-left:8px; width:30px;" maxlength="1" size="1" id="pinform">
<input type="text" name="pinnew-4" style="margin-left:8px; width:30px;" maxlength="1" size="1" id="pinform">
<span class="help-block" style="float:right;"><small>Je gewenste PIN. Het beste is vier <strong>niet identieke</strong> Getallen.</small></span>
</div></div>
<label class="control-label" for="inputEmail">Herhaal Nieuwe PIN</label>
<div class="form-group">
<div class="col-lg-10">
<input type="text" name="pinnewrep-1" style="width:30px;" maxlength="1" size="1" id="pinform">
<input type="text" name="pinnewrep-2" style="margin-left:8px; width:30px;" maxlength="1" size="1" id="pinform">
<input type="text" name="pinnewrep-3" style="margin-left:8px; width:30px;" maxlength="1" size="1" id="pinform">
<input type="text" name="pinnewrep-4" style="margin-left:8px; width:30px;" maxlength="1" size="1" id="pinform">
<span class="help-block" style="float:right;"><small>Herhaal je nieuwe gewenste PIN. Dit is om fouten te <strong>voorkomen<strong>.</small></span>
</div></div>
<hr>
<div class="form-group">
<div class="col-lg-10">
<button name="pin-submit" type="submit" class="btn btn-primary">Opslaan</button>
</div>
</div>
</form>
Vielen Dank im Voraus, Pascal
So eine dieser Variablen müssen leer sein. Was enthalten all diese Variablen? Überprüfen Sie auch das Handbuch http://php.net/manual/en/function.empty.php auf etwas, das als "leer" gilt. 'Die folgenden Dinge gelten als leer: eine leere Zeichenfolge, 0 als Ganzzahl, Zeichenfolge oder Gleitkommazahl, NULL, FALSE, ein leeres Array, eine deklarierte Variable, aber ohne Wert. – chris85
Hallo, ich habe alle Variablen gepoolt . Keine von ihnen ist leer. Sie alle geben eine Single Number wieder. Jede Variable sollte 1 Nummer enthalten, die korrekt ist. –
@ chris85 Das ist möglich. Sie können auch "0" sein. Ist PHP 'leer()'. Richtig, das gilt als leer? Gibt es Alternativen, um auch "0" zuzulassen? –