Jump to content

Recommended Posts

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";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/183953-sql-query-not-getting-the-field-values/
Share on other sites

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'"; 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.