Reputation: 57
When I fill out this form and submit the value nothing happens, but when I pass only 1 value at a time the value go through, so what am I doing wrong.
HTML:
<form action="" method="post">
<label for="kafli">Kafli:</label>
<select name="kafli" id="kafli">
<option value=""></option>
<option value="11">1.1</option>
<option value="12">1.2</option>
<option value="13">1.3</option>
<option value="14">1.4</option>
<option value="15">1.5</option>
<option value="16">1.6</option>
</select>
<label for="html">HTML:</label>
<textarea name="html" id="html"></textarea>
<input type="submit" value="Deila">
</form>
PHP
if(isset($_POST['html'])) {
echo 'HTML is OK';
if(isset($_POST['kafli'])) {
echo 'Kafli is OK';
}
}
Upvotes: 1
Views: 100
Reputation: 74217
If you want to echo both conditions to ensure they're not empty, then use empty()
and not isset()
.
Using <select>
and <textarea>
already assumes they're "set". What you're looking to use and being the better method, is a conditional empty()
.
if(isset($_POST['submit'])){
if(!empty($_POST['html'])) {
echo 'HTML is OK';
if(!empty($_POST['kafli'])) {
echo 'Kafli is OK';
}
}
else{
echo "one or all are empty";
}
} // brace for submit
While naming your submit button: (for the added conditional statement I added in the first example)
<input type="submit" name="submit" value="Deila">
Or, use a conditional statement for both, using the && - AND
operator:
I.e.:
if(!empty($_POST['html']) && !empty($_POST['kafli'])) {
echo 'Both are filled.';
}
else{
echo "One or both were not filled";
}
Or, using the OR - ||
operator
if(!empty($_POST['html']) || !empty($_POST['kafli'])) {
echo "One was filled, but not the other";
}
References:
Upvotes: 1