John Ellee Robado

Greenhorn
+ Follow
since Sep 25, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
1
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John Ellee Robado

How do you insert data in the database using checkbox inside table in every table data using PHP?

Function to get the time range

function create_time_range($start, $end, $interval='30 mins', $format='12'){
$startTime=strtotime($start);
$endTime=strtotime($end);
$returnTimeFormat=($format=='24')?'g:i':'G:i';

$current=time();
$addTime=strtotime('+'.$interval,$current);
$diff=$addTime-$current;

$times=array();
while ($startTime<$endTime) {
$times[]=date($returnTimeFormat,$startTime);
$startTime+=$diff;
}
$times[]=date($returnTimeFormat,$startTime);
return $times;
}

Here is my code in table

<table class="table table-bordered table-hoverable table-striped" id="tblClassScheduler">
                   <thead>
                      <tr>
                        <?php
                         $days=array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
                         for ($i=0;$i<COUNT($days);$i++) {
                          echo "<th>".$days[$i]."</th>";
                         }
                      ?>
                      </tr>
                   </thead>
                   <tbody>
                    <form method="POST">
                    <?php
                    $class_time_schedule=create_time_range("08:00","22:00", $interval='30 mins', $format='12');
                    foreach ($class_time_schedule as $time_schedule) {
                    echo "<tr>";
                    for ($i=0;$i<COUNT($days);$i++) { ?>
                    <td><?php echo $time_schedule; ?><br>
                    <input type="checkbox" name="class_time[]" value="<?php echo $time_schedule; ?> ">
                    <input type="text" name="class_day[]" value="<?php echo $days[$i]; ?>" hidden>
                    </td>
                   
                    <?php  }
                    echo "</tr>";
                    }
                    ?>
                    <button type="submit" class="btn btn-primary" name="save_schedule">Save</button>
                    </form>
                   </tbody>
               </table>

My PHP code to insert data in the database

$days=array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
if (isset($_POST['save_schedule'])) {
$class_time=$_POST['class_time'];
$class_day=$_POST['class_day'];
for ($x=0;$x<COUNT($class_time);$x++) {
$class_time_sched=$class_time[$x];
$class_day_sched=$class_day[$x];
insertQuery("INSERT INTO acadsoc_class_schedule(username,class_time,class_day,date_created) VALUES (?,?,?,?)",
array($_SESSION['username'],$class_time_sched, $class_day_sched, date("Y-m-d")));
}
}

3 weeks ago
PHP
Look at codes on the top of the image, It's not working properly I can't insert in the database
1 month ago
PHP
<form method="POST">
               <table class="table table-bordered table-hoverable table-striped" id="tblClassScheduler">
                   <thead>
                      <tr>
                        <?php
                         $days=array("Monday"=>1,"Tuesday"=>2,"Wednesday"=>3,"Thursday"=>4,"Friday"=>5,"Saturday"=>6,"Sunday"=>7);
                         for ($i=0;$i<COUNT($days);$i++) {
                           echo "<th>".date("D m/d",strtotime(" +".$i." days"))."</th>";
                         }
                      ?>
                      </tr>
                   </thead>
                   <tbody>
                    <?php
                    $class_time=create_time_range('08:00','22:00','30 mins');
                    $j=0;
                    foreach ($class_time as $value) {
                    $j++;
                    echo "<tr>
                    <td><input type='text' name='class_time[]' value='".$value."' hidden>".$value."</td>
                    <td><input type='text' name='class_time[]' value='".$value."' hidden>".$value."</td>
                    <td><input type='text' name='class_time[]' value='".$value."' hidden>".$value."</td>
                    <td><input type='text' name='class_time[]' value='".$value."' hidden>".$value."</td>
                    <td><input type='text' name='class_time[]' value='".$value."' hidden>".$value."</td>
                    <td><input type='text' name='class_time[]' value='".$value."' hidden>".$value."</td>
                    <td><input type='text' name='class_time[]' value='".$value."' hidden>".$value."</td>
                    </tr>";
                    }
                    ?>
                   </tbody>
                   <button type="submit" class="btn btn-primary" id="save_class_schedule" name="save_class_schedule">Save</button>
               </table>
               </form>
1 month ago
PHP