Jump to content

Recommended Posts

Hi,

I have database stored a field of date. I want to check if the date in the DB field is the same as the current date, how to do it?

Code:

$oracle = mysqli_real_escape_string($con, $_POST['oracle']);
$query 	= mysqli_query($con, "SELECT indate FROM staff WHERE OracleID ='$oracle'");
$row	= mysqli_fetch_array($query);
$num_row = mysqli_num_rows($query);
		
	if ($num_row > 0) 
	{	
		$curdate = date();
		if ($row['indate'] !== $curdate)
		{
			$query1=mysqli_query($con, "update staff set ClockedIn = 0, ClockedOut = 0 where OracleID='$session_id'")or die('Error In Session');
			header('location:home.php');				
		}
	}

 

db date.png

Link to comment
https://forums.phpfreaks.com/topic/310248-check-db-date-with-current-date/
Share on other sites

You should really check the num-rows value before you attempt to do a fetch.  Doesn't that make more sense?  Perhaps you should also check that the query call itself succeeded before doing that also.  Something like:

	if (query succeeded)
	     if (num_rows test)
	    {
	         (fetch)
	        (process results)
	    }
	

Edited by ginerjm
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.