I am working on a website which reserves lot for clients. Lot reserved has expiration date. In localhost, everything works fine. The system date and time is what my website is getting. But when I tested it online (I uploaded my website) it's not getting the system date and time.
$d = date('d M Y h:i A'); //TODAYS DATE---> this doesnt change when I change my PC's date and time
$curdate = strtotime($d)*1000;
echo $d;
$sql = "SELECT * FROM reservation";
$res = $conn->query($sql);
foreach ($res as $row) {
$exp = strtotime($row['expiration'])*1000;
$lot = $row['lot'];
$sqli = "SELECT * FROM reservation WHERE ".$curdate." >= ".$exp." AND status='reserved'";
$resu = $conn->query($sqli);
foreach ($resu as $ro) {
$id = $ro['reserve_id'];
$sl = "DELETE FROM reservation WHERE reserve_id='$id'";
$conn->query($sl);
$l = substr($ro['lot'], 1);
echo "<script>$(document).find('#_".$l."').css({'fill':'#848484'});</script>";
}
}
PHP uses the time for the machine it's running on "Server", still you can get the time from the client machine using javascript/jquery -ajax call like :
var TimeNow = new Date();
$.ajax({
url : url,
data : {date : TimeNow}
});
Related
Hello I want to update MySQL table automatic at set time like i want to update table at 5:30 i have some values to update in my database at set time automatic. in PHP
$date = date('H:i:s');
if($date == "11:26:00") // 17:30:00 is equal to 5:30 but in 24 system
{
$sql1 = "SELECT * FROM No where id='1'";
$result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());
while($row= mysqli_fetch_assoc($result1))
{
$Foo= $row['foo'];
}
$sql2 = "UPDATE No SET id='2',foo='$foo' where id='2'";
$result2 = mysqli_query($mysqli,$sql2) or die(mysqli_error());
}
Just lie what Ashish said you can use CRON , and if you want you maybe can use this , i did not use before , try it . This code will works once ,so you have to find away to make loop cause the time will change every sec .
Note : Check the second code .
<?php
// Database connect
$date = date('H:i:s'); // Set the time to hours and minutes and seconds format
// you can echo $date to check how it looks but it will be something like this : 07:21:48
if($date == "17:30:00") // 17:30:00 is equal to 5:30 but in 24 system
{
// You can type your code here .
}
?>
Second Code :
<?php
// Remember to connect to your database
$date1 = date_create("00:00");
$date2 = date_create("23:59");
while($date1<=$date2)
{
date_add($date1,date_interval_create_from_date_string("1 sec"));
$a = date_format($date1,"H-i-s");
if($a =='17:30:00')
{
$sql1 = "SELECT * FROM No where id='1'";
$result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());
$row= mysqli_fetch_assoc($result1)
{
$Foo= $row['foo'];
$sql2 = "UPDATE No SET id='2',foo='$foo' where id='2'";
$result2 = mysqli_query($mysqli,$sql2) or die(mysqli_error());
}
die;
}
else
{
// you can type anything here , you can end the process by typing die; or anything you want
}
}
?>
You can check this and see how you can loop throw date in php :
I have 2 dates in PHP, how can I run a foreach loop to go through all of those days?
This can help you understand the time and date system and how to change the format for the date in php : How to get the current date and time in PHP?
I want all serialNo from registration table and then send it back to device. I try this:
date_default_timezone_set ('Asia/Phnom_Penh');
// Create a header with the current time
header('Last-Modified: ' . date("D, d M Y H:i:s", time()) . ' GMT+7');
$query1 = mysql_query("select serialNo from registration");
$row = mysql_fetch_array($query1);
$serialsArray = Array($row['serialNo']);
$tag = '';
if(!empty($_GET['passesUpadatedSince'])){
$tag = strtotime($_GET['passesUpadatedSince']);
error_log('Tag: ' .$tag,0);
}
$query1 = mysql_query("select MAX(updateTag) as updateTag from digiCardPass");
$row1 = mysql_fetch_array($query1);
$updateTag = $row1['updateTag'];
error_log("get serial method");
//if (!empty($serialsArray) && $updateTag != $tag) {
if (!empty($serialsArray)) {
echo json_encode(array('lastUpdated' => (string)time(),
'serialNumbers' => $serialsArray));
}else {
response(204);
}
}
?>
But when I send serial, I see only 1 serial. This is the result: May 7 17:01:05 ML-iphone-5 passd[4234] <Warning>: Get serial numbers task completed with update tag 1367920864, serial numbers (
1
)
How can I get all serial ?
You should be using mysqli as the mysql_* is deprecated, but anyway...
You only see one result because you use:
$row1 = mysql_fetch_array($query1);
$updateTag = $row1['updateTag'];
You need something like this:
while ($row = mysql_fetch_row($query1))
{
// do something sensible with each one here
echo $row['updateTag'];
}
Because each device has own deviceID, so I just change : $query1 = mysql_query("select serialNo from registration where deviceID = '$deviceID'");
and now everything works like what I want !
I'm working on an online booking system, so I have a php script that receives a date and will output an array of possible timeslots that are free on that date. I'm trying to make it so that when closing the datepicker it sends the variables to the file and retrieves the result. At the moment the submit button also leads to the php file, and will show me available slots when I choose a date. The php part works, but when I add events to the datepicker it won't submit any variables to the php file. I think this is also the cause that when I add another load.('input_date.php'); I get the full timeslot list caused by the if(isset... Can anyone tell me why jQuery is ruining my variable posting? Thanks in advance..
$(document).ready(function() {
$("#dates").load('input_date.php');
$("#datepicker").datepicker({onClose: function() {
$.post("input_date.php", $('#datepicker').serialize());
alert(1);
}});
});
This is the php file:
<?php
include('connection.php');
error_reporting(0);
$treatment = $_POST['treatment'];
$bookdate = $_POST['bookdate'];
if(isset($treatment) && isset($bookdate)){
$exp = explode("-", $bookdate);
//determine what day of the week it is
$timestamp = mktime(0,0,0,$exp[1],$exp[0],$exp[2]);
$dw = date( "w", $timestamp); // sun0,mon1,tue2,wed3,thur4,fri5,sat6
echo $dw."weekday"; //week day
echo"<br/>";
//find bookings with same date
$q = mysql_query("SELECT BOOK_SLOT_ID FROM BOOKINGS WHERE BOOK_DATE='$bookdate'");
//make array of booking slots
$array1 = array();
while ($s = mysql_fetch_array($q)) {
$array1[] = $s['BOOK_SLOT_ID'];
}
$q2 = mysql_query("SELECT SL_ID FROM SLOTS");
//make array of all slots
$array2 = array();
while ($s2 = mysql_fetch_array($q2)) {
$array2[] = $s2['SL_ID'];
}
//remove bookings from all slots
$arr_res = array_diff($array2, $array1);
//make selectable options of results
echo "<SELECT>";
foreach($arr_res as $op){
$r = mysql_query("SELECT SL_TIME FROM SLOTS WHERE SL_ID='$op'");
$q3 = mysql_fetch_array($r);
echo "<OPTION value=".$op.">".$q3['SL_TIME']."</OPTION>";
}
echo "</SELECT>";
}else{
$else = mysql_query("SELECT * FROM SLOTS");
echo "<SELECT>";
while($array_else = mysql_fetch_array($else)){
echo "<OPTION value=".$array_else['SL_ID'].">".$array_else['SL_TIME']."</OPTION>";
}
echo "</SELECT>";
}
?>
I believe it is because you have this line of code:
$('#datepicker').serialize()
This should be changed to the id of the form not the datapicker. In your PHP you are trying to get two seperate values:
$treatment = $_POST['treatment'];
$bookdate = $_POST['bookdate'];
Right now you are just sending the value of the input field #datepicker.
sorry to post this but have been struggling now for 8 days and really hope someone can help as I am at the end. I have json.html & xxjson-events.php in same directory, both file content posted below.
json.html
<script type="text/javascript">
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
$('#calendar').fullCalendar({
eventSources: [
// your event source
{
url: '/xxjson-events.php' // use the `url` property
}
]
});
</script>
xxjson-events.php
<?php
mysql_select_db($database_ghl_portal, $ghl_portal);
$query_rsXXCal = "SELECT * FROM events";
$rsXXCal = mysql_query($query_rsXXCal, $ghl_portal) or die(mysql_error());
$row_rsXXCal = mysql_fetch_assoc($rsXXCal);
$totalRows_rsXXCal = mysql_num_rows($rsXXCal);mysql_select_db($database_ghl_portal, $ghl_portal);
$query_rsXXCal = "SELECT * FROM events";
$rsXXCal = mysql_query($query_rsXXCal, $ghl_portal) or die(mysql_error());
$row_rsXXCal = mysql_fetch_assoc($rsXXCal);
$totalRows_rsXXCal = mysql_num_rows($rsXXCal);
$result = mysql_query($query_rsXXCal) or die(mysql_error());
while($row = mysql_fetch_assoc($result)){
$eventsArray = array();
$eventsArray['title'] = $row['title'];
$eventsArray['start'] = $row['start_date'];
$eventsArray['end'] = $row['end_date'];
}
echo json_encode($eventsArray)
?>
json-events.php viewed in browser shows:
{"title":"TEST","start":"2012-02-23 00:00:00","end":"2012-02-24 00:00:00"}
The calendar shows on page however data does not pull through to the calendar? has anyone any ideas at all why this could be please, really struggling with this and need to sort. I thought it may be the datetimestamp showing 00:00:00 but changed this with no success?
If it helps anyone I have uploaded a zip containing 3 files to see if it works for anyone else? http://ghldatastream.co.uk.predns.ourwindowsnetwork.com/fullcal_json.zip
Thanks
Your start and end date have to be in IETF, ISO8601 or UNIX timestamp format - see http://arshaw.com/fullcalendar/docs/event_data/Event_Object/
I have this on my login page:
$current_time = date("g:i A");
$current_date = date("l, F jS, Y");
mysql_query("UPDATE employees
SET last_login = '$current_time', last_login_date = '$current_date' WHERE username='$username' AND password='$password'");
And then on the page when the user is logged in (the protected page) I have this:
[...]
<?php
$last_login_date = $info['last_login_date']; // get last_login_date from mysql table
$last_login_time = $info['last_login_time']; // get last_login_time from mysql table
?>
[...]
You last signed in on <?php echo $last_login_date; ?> at <?php echo $last_login_time; ?>.
But this doesn't work properly because it shows the time they just logged in. How can I make it show the last time they logged in?
I also even tried adding a prev_login_time and prev_login_date to the table too, but I don't know how to make it update properly because it would update every time they login making it show the time they just logged in. (so it would be showing the current time to them)
Thanks.
Edit: [for EdoDodo]
Here's the login if statement that is setting the last IP address session variable:
if($_POST['submit']) {
$sql = "SELECT * FROM employees WHERE username='$username' and password='$password'";
$result = mysql_query($sql);
$count = mysql_num_rows($result);
$info = mysql_fetch_array($result);
if($count == 1) {
$_SESSION['loggedin'] = 1;
$_SESSION['user'] = $username;
$_SESSION['last_login_time'] = $info['last_login'];
$_SESSION['last_login_date'] = $info['last_login_date'];
$_SESSION['last_ip'] = $info['last_login_ip'];
$return = $_SESSION['returnurl'];
if(!$return) {
$return = "/employee/";
}
date_default_timezone_set('America/New_York');
$current_time = date("g:i A");
$current_date = date("l, F jS, Y");
$ip = $_SERVER['REMOTE_ADDR'];
mysql_query("UPDATE employees
SET last_login = '$current_time', last_login_date = '$current_date', last_login_ip = '$ip' WHERE username='$username' AND password='$password'");
header("Location: $return");
exit();
}
The last login date and time is working, which is why I don't know why it isn't working with the IP one. I am accessing it correctly on the protected page:
$last_login_date = $_SESSION['last_login_date'];
if($last_login_date = date("l, F jS, Y")) {
$last_login_date = "Today";
}
$last_login_time = $_SESSION['last_login_time'];
if($_SESSION['last_ip'] != $_SERVER['REMOTE_ADDR']) {
$last_login_ip = "this IP address (".$_SERVER['REMOTE_ADDR'].")";
}
else {
$last_login_ip = "IP address ".$_SESSION['last_ip'];
}
echo "Last account login: ".$last_login_date." at " . $last_login_time . " from " . $last_login_ip . ".";
Am I doing something wrong? Maybe I'm not setting the session variable or retrieving it properly? But it seems like I am. I hope you can help. Thanks in advance.
You'll want to fetch the login time from the table in the database into the $info array before you update the database and overwrite the time with the new one. Then, you'll have the previous login time in the $info array (and, if you want to carry it across lots of different page loads, you could put it in a session variable).