i want to make a button in an attendance table when the user click on this button the current time appears as a departure time for customer and how to save this time in my database. here's my code.
Code:
<?php
$con=mysql_connect("localhost","root","admin");
mysql_query("set character_set_server='utf8'");
mysql_query("set names 'utf8'");
if(!$con)
{
die('couldnot connect:');
}
mysql_select_db("santirino",$con);
@$user_id = $_POST['ID'];
echo "
<table class='bordered' align='center'> <thead> <tr> <th style='text-align:center;' nowrap='nowrap'> وقت الأنصراف </th> <th style='text-align:center;' nowrap='nowrap'> وقت الحضور </th> <th style='text-align:center;' nowrap='nowrap'> التاريخ </th> <th style='text-align:center;' nowrap='nowrap'> اسم العضو </th> <th style='text-align:center;' nowrap='nowrap'> رقم العضو </th> <th style='text-align:center; height='10px';' nowrap='nowrap'> المسلسل </th> </tr> </thead>
";
echo $today = date("20y-m-d"). " ";
$todayDate = date("Y-m-d g:i a");// current date
$currentTime = time($todayDate); //Change date into time
$timeAfterOneHour = $currentTime+60*60;
echo $time = date("H:i:s",$timeAfterOneHour);
if($time >= "16:00:00")
{
$sql="select * from members where id = '$user_id'";
$result = mysql_query($sql);
$get_all="select * from attendance where date = '$today'";//select all members in current date
$result_getall = mysql_query($get_all);
$i;
echo "<br />";
while($row = mysql_fetch_array($result))
{
@$i++;
mysql_query("set character_set_server='utf8'");
mysql_query("set names 'utf8'");
$query_sql = "INSERT INTO attendance (id,date,name,time) VALUES ('$user_id','$today','$row[name]','$time')";
$res = mysql_query($query_sql);
echo "<tr>"
."<td style='text-align:center;'><form><button>انصرف</button></form></td>"
."<td style='text-align:center;'>".$time."</td>"
."<td style='text-align:center;'>".$today."</td>"
."<td style='text-align:center;' nowrap='nowrap'>".$row['name']."</td>"
."<td style='text-align:center;' nowrap='nowrap'>".$row['id']."</td>"
."<td style='text-align:center;' nowrap='nowrap'>".$i."</td>"
."</tr>";
}
while($row = mysql_fetch_array($result_getall))
{
if($row['id'] == $user_id)
{
echo "<script> alert('العضو مسجل بالفعل') </script>";
}
else
{
@$i++;
echo "<tr>"
."<td style='text-align:center;'><form><button>انصرف</button></form></td>"
."<td style='text-align:center;' nowrap='nowrap'>".$row['time']."</td>"
."<td style='text-align:center;' nowrap='nowrap'>".$row['date']."</td>"
."<td style='text-align:center;' nowrap='nowrap'>".$row['name']."</td>"
."<td style='text-align:center;' nowrap='nowrap'>".$row['id']."</td>"
."<td style='text-align:center;' nowrap='nowrap'>".$i."</td>"
."</tr>";
}
}
}
Comment