Jump to content

$sql query not getting the field values


tourer

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.