tourer Posted December 4, 2009 Share Posted December 4, 2009 hey friends . I have written a code where i want to compare the Server Current Time & Date with the Start_date, starttime & endtime fetched from the database. but i am finding some trouble with the sql query. The sql query for the field resid is working, but its not fetching start_date, starttime & endtime. the resid is entered by the user which is compared withe one in datebase. Aftere which the Start_date & Current date are compared on the backend. Can anyone please help me out of this: <?php require_once('lib/ReservationTime.class.php'); date_default_timezone_set('Asia/Kolkata'); $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'XXX'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'phpscheduleit'; mysql_select_db($dbname,$conn) or die ("could not open db".mysql_error()); // set values to user defined starting day of week $dv = array(); $today = getdate(); $dv['month'] = $today['mon']; $dv['day'] = $today['mday']; $dv['year'] = $today['year']; $default = true; // Make timestamp for today's date $dv['todayTs'] = mktime(0,0,0, $dv['month'], $dv['day'], $dv['year']); $Tdate = date('H') * 60 + date('i'); $userId = $_POST['resid1']; $sql = "SELECT 'resid', 'start_date', 'starttime', 'endtime' FROM reservations WHERE resid = '$userId'"; $result = mysql_query($sql) or die('Query failed. ' . mysql_error()); if (mysql_num_rows($result) == 1) { if ($dv['todayTs'] == "$start_date"){ if($Tdate >= "$starttime" && $Tdate < "$endtime") { echo "www.localhost/e1.html(user should navigate to this page)"; } else { echo "This is not your time slot"; }}else { echo "Your slot is booked for some other day"; }}else{ echo "Wrong Reservation id"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/183953-sql-query-not-getting-the-field-values/ Share on other sites More sharing options...
tourer Posted December 4, 2009 Author Share Posted December 4, 2009 Me too require some shweet little help moderators. Quote Link to comment https://forums.phpfreaks.com/topic/183953-sql-query-not-getting-the-field-values/#findComment-971059 Share on other sites More sharing options...
rajivgonsalves Posted December 4, 2009 Share Posted December 4, 2009 what is your start_date field format, also your sql is wrong $sql = "SELECT 'resid', 'start_date', 'starttime', 'endtime' FROM reservations WHERE resid = '$userId'"; should be $sql = "SELECT resid, start_date, starttime, endtime FROM reservations WHERE resid = '$userId'"; Quote Link to comment https://forums.phpfreaks.com/topic/183953-sql-query-not-getting-the-field-values/#findComment-971062 Share on other sites More sharing options...
tourer Posted December 4, 2009 Author Share Posted December 4, 2009 The Start_date is stored in a Unix timestamp format. such as for yesterday, it shows 1259778600 as date. and start & end time are converted in minutes, i:e: for 3.00 pm it shows 900 in the DB. Quote Link to comment https://forums.phpfreaks.com/topic/183953-sql-query-not-getting-the-field-values/#findComment-971065 Share on other sites More sharing options...
tourer Posted December 4, 2009 Author Share Posted December 4, 2009 Moreover i need to get these values from the database and compare them to the current server time & date. is there any other function which i am supposed to use. Please help. Quote Link to comment https://forums.phpfreaks.com/topic/183953-sql-query-not-getting-the-field-values/#findComment-971099 Share on other sites More sharing options...
fenway Posted December 4, 2009 Share Posted December 4, 2009 Assuming you can get these back to timestamps, mysql has function that can convert back & forth -- but why bother to begin with? Quote Link to comment https://forums.phpfreaks.com/topic/183953-sql-query-not-getting-the-field-values/#findComment-971253 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.