0

here i am creating a attendance sheet that insert data into the database after clicking submit button. The insertion of the data is base on the 2 radio button which is absent/present, the problem is after clicking submit button the other component works accordingly except for the dropdown button, the dropdown button insert only a single string instead of the service time by the way i declare the service time in the database as varchar so i am confident that it's not the database that causes the error. maybe someone can help me any help is much appreciated. thank you in advance
enter code here

<?php
include("Sampledb.php");
include("Sample.php");
$flag=0;
if(isset($_POST['submit']))
{
    foreach($_POST['attendance_status'] as $id1=>$attendance_status)
        {
        $name=$_POST['name'][$id1];
        $id=$_POST['id'][$id1];
        $date=date("Y-m-d H:i:s");  
        $servicetime=$_POST['servicetime'][$id1];


        $result=mysqli_query($objconn,"insert into 
        attendrecord(id,name,attendance_status,attendance_date,servicetime)

        values('$id','$name','$attendance_status','$date','$servicetime')");            
            if($result)
            {
                $flag=1;
            }                   

        }
    header("Location:sampleindex.php");
    exit;
}
?>

<div class="panel panel-default">
<div class="panel panel-heading">

<form action="sampleindex.php" method="Post"> 

<label>Service time:</label>
<select name="servicetime">
<option>00:00</option>
<option value="7:30-9:30">7:30-9:30</option>
<option value="10:30-12:30">10:30-12:30</option>
<option value="1:30-3:30">1:30-3:30</option>
<option value="4:30-6:30">4:30-6:30</option>
</select>

<a class="btn btn-info pull-right" href="view.php">View all<a/>


</div>
</div> 

<div id="alert" style="display:none;" class="alert alert-success" ">
<a href="#" class="close" data-dismiss="alert">&times;</a>
<strong>Success!</strong>Save
</div>

<h3>
<div class="well text-center">Date:<?php echo date("Y-m-d"); ?> </div>
</h3>

<div class="panel panel-body">


<tr>
<table class="table table-striped">
</tr>

<th>ID Number</th><th>Member Name</th><th>Attendace Status</th> 
<?php $result=mysqli_query($objconn,"select* from attend");
$id = 0;
$counter=0;
while($row=mysqli_fetch_array($result))
{
$id++;
?>


<tr>
<td><?php echo $row['id']; ?></td>
<input type="hidden" value="<?php echo $row['id']; ?>"name="id[]">
<td><?php echo $row['name']; ?></td>
<input type="hidden" value="<?php echo $row['name']; ?>"name="name[]">
<td> 
<input type="radio" name="attendance_status[<?php echo $counter; ?>]" 
value="present">Present
<input type="radio" name="attendance_status[<?php echo $counter; ?>]" 
value="absent">Absent
</td>
</tr>   
<?php
$counter++;
}

?>
</table>    

<input type="submit" name="submit" value="submit" onclick="return mess();">

</div>

<script type="text/javascript">
function mess()
{
    if($flag=1){
    alert ("Record Save!");
    return true;}
    else
    alert ("Record Not Save!");
}
</script>
<script type="text/javascript">
$(document).ready(function(){
    $('#submit').click(function(){
        $('#alert').css('display','block');
    });
});
</script>
</div>  
</div>  
1
  • sorry about the indention sir, it's my first time to post question here but in my actual code is properly indented but still thanks for the advice ill take note about it.. Commented Feb 24, 2019 at 14:40

2 Answers 2

1

Your service time is not an array as it keeps same for all record. So you need to change your PHP code as below:

$servicetime=$_POST['servicetime'];

Hope it helps you.

Sign up to request clarification or add additional context in comments.

2 Comments

thanks a lot sir that's really work .. your a life saver hahahhahhaa
Great, happy that it helped you :)
0

Instead of $_POST['servicetime'][$id] use $_POST['servicetime']

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.