I have a database wich looks like this:
+----------+----------+---------+----------+
| bogie_id | train_id | axle_nr | bogie_nr |
+----------+----------+---------+----------+
| 1 | 1 | 1 | |
| 2 | 1 | 2 | |
| 3 | 1 | 3 | |
| 4 | 1 | 4 | |
+----------+----------+---------+----------+
As you can see the "bogie_nr"
rows are empty.
No i wana make an if statement, wich checks if the rows are empty or filled in.
What i currently have:
<div id="bogiebox">
<tr>
<?php
$x = 1;
foreach($show_axle as $bogiebox){ ?>
<input type='hidden' name='bogie_id[<?php echo $bogiebox['bogie_id']?>]' value='<?php echo $bogiebox['bogie_id']?>'>
<td>
<?php
if($bogiebox['bogie_nr'] == ''){
?>
<input type='checkbox' id="bogie_axle_fields" value="<?= $x ?>" name='bogie_nr[<?php echo $bogiebox['bogie_id']?>]'></td>
<?php
}
else{
?>
<input type='checkbox' id="bogie_axle_fields" checked disabled></td><?php } }
?>
</tr>
</div>
And then the if statement:
<?php
if(isset($_POST['y'])){
$bogiefilledin = false;
if(!empty($_POST['bogie_nr'])) {
echo "everything is full?";
}
else {
echo "Fill in some more fields";
}
}
?>
It is not done yet! but what it should do is:
We check a checkbox or 2. press the send button, and the database inserts the number 1 for the 2 selected bogies. Then the page refeshes and all the checkboxes should have a value of 2. And on the next insert they will insert the value 2. and so on and so on.
But, what i would like = if i filled in my database like this:
+----------+----------+---------+----------+
| bogie_id | train_id | axle_nr | bogie_nr |
+----------+----------+---------+----------+
| 1 | 1 | 1 | 1 |
| 2 | 1 | 2 | 1 |
| 3 | 1 | 3 | 2 |
| 4 | 1 | 4 | |
+----------+----------+---------+----------+
I would like to see the else statement (Fill in some more fields). because the 4th axle is not in a bogie yet.
Right now the if else statement shows me: when i select 1 and press submit it says: "everything is full!" . and when i select nothing it says: "Fill in some more fields.". However it does not insert anything yet, so it should always say: Fill in some more fields!.
How do i do this??
try changing
if(!empty($_POST['bogie_nr']))
to thisif($_POST['bogie_nr']!='')