How to get today's date and compare it with database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tutusaint
    New Member
    • Sep 2010
    • 18

    How to get today's date and compare it with database

    I have a login script to authenticates with email address and password.
    I want this script to also check the date stored in the users profile against current date. if the date are same, it redirects to an error page.

    Bellow are my authentication script.

    Code:
    <?php
    include "dbCon.php";
    
    $EmailAd = $_POST['EmailAd'];
    $Password = $_POST['Password'];
    
    $query = mysql_query("SELECT * from user where EmailAd = '$EmailAd'
    						AND Password = '$Password'");
    						
    $row = mysql_fetch_array($query);
    
    if ($row) {
    	session_start();
    	$_SESSION['EmailAd'] = $_POST['EmailAd'];
    	header ('Location: home.php');
    	exit();
    	}
    else {
    	header ('Location: loginFailed.php');
    	exit();
    	}
    ?>
    Please help
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    What format is the date stored in?

    Comment

    • tutusaint
      New Member
      • Sep 2010
      • 18

      #3
      thanks for your quick reply.
      Date format : dd/mm/yyyy

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        OK - so grab the current date and then compare it, like so:

        Code:
        $current_date = date('d/m/Y');
        // I'm assuming $row['date'] is correct
        if ($row['date'] == $current_date)
        {
          echo "Dates match"; 
          // Do something
        }
        else
        {
          echo "Dates don't match";
        }
        Mark.

        Comment

        • tutusaint
          New Member
          • Sep 2010
          • 18

          #5
          Hello Mark,
          Pls i am having a problem integrating it into the script i posted.
          Please help me integrate it so i can learn from it.
          Pls

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            I won't do it for you - I have given you enough details for you to do it yourself.

            Comment

            • tutusaint
              New Member
              • Sep 2010
              • 18

              #7
              Thanks Mark.

              I will figure it out myself.

              Comment

              • tutusaint
                New Member
                • Sep 2010
                • 18

                #8
                Registeration with date

                I have a registration script.
                I want to capture the current date in this format dd/mm/yyyy.

                Below is the registration code

                Code:
                <?php
                
                if (isset($_POST['Submit'])) {
                
                include "dbCon.php";
                
                $EmailAd = $_POST['EmailAd'];
                $Password = $_POST['Password'];
                $Name = $_POST['Name'];
                $Age = $_POST['Age'];
                $Gender = $_POST['Gender'];
                $Bday = $_POST['Bday'];
                $Phone = $_POST['Phone'];
                $College = $_POST['College'];
                $Course = $_POST['Course'];
                $Yr = $_POST['Yr'];
                $UserType= $_POST['UserType'];
                $Address= $_POST['Address'];
                $Interest = $_POST['Interest'];
                $Affiliation = $_POST['Affiliation'];
                $Schedule = $_POST['Schedule'];
                $About = $_POST['About'];
                $Who = $_POST['Who'];
                
                $query = mysql_query("INSERT into user (EmailAd, Password, Name, Age, Gender, Bday, Phone, College, Course, Yr, UserType, Address, Interest, Affiliation, Schedule, About, Who)
                					VALUES('$EmailAd', '$Password', '$Name', '$Age', '$Gender', '$Bday', '$Phone', '$College', '$Course', '$Yr', '$UserType', '$Address', '$Interest', '$Affiliation', '$Schedule', '$About', '$Who')");
                
                if ($query) {		
                	session_start();
                	$_SESSION['EmailAd'] = $_POST['EmailAd'];                                  
                	header ('Location: registerSuccess.php');
                	}
                else {
                	echo ('Failed to Input Data');
                	}
                }
                ?>
                Please help.

                Comment

                • Markus
                  Recognized Expert Expert
                  • Jun 2007
                  • 6092

                  #9
                  Please do not create separate threads on the same topic.

                  I showed you how to get the current time in post #4.

                  Comment

                  Working...