appear time onclick a button and save the time in a database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • setovan
    New Member
    • Nov 2012
    • 4

    appear time onclick a button and save the time in a database

    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>";
    		}
    	}
    }
    Last edited by Rabbit; Nov 28 '12, 02:39 AM.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    There's a lot of code there. Which part are you having trouble with? I see code in there already to insert data into the database so I'm not sure what it is you're struggling with.

    Comment

    Working...