Registration date

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

    Registration date

    I am having issues with my registration date.
    I need to capture the registration date of a user and compute the expiry date but my script is not capturing both the date and expiry date.

    I have posted my scripts here for you.

    Please help.

    Code:
    <?php
    
    if (isset($_POST['Submit'])) {
    //$Bday  = date("dd-mm-yyyy");
    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'];
    $now=date ("Y-m-d"); //store current date to a variable. this is used for scratch card expiration processes
    $exp=date ("Y-m-d", mktime (0,0,0,date("m")+12,(date("d")+0),date("Y"))); //set expiry date of user to 12months the date of account creation
    
    
    $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', Regdate='$now',  expire='$exp'))");
    
    // $sql= "INSERT INTO user SET Regdate='$now',  expire='$exp'";
    
    if ($query) {		
    	session_start();
    	$_SESSION['EmailAd'] = $_POST['EmailAd'];                                  
    	header ('Location: registerSuccess.php');
    	}
    else {
    	echo ('Failed to Input Data');
    	}
    }
    ?>
  • HaLo2FrEeEk
    Contributor
    • Feb 2007
    • 404

    #2
    I'm not sure why you sent me a PM as well as posting it here, but I'll just copy my reply to the PM here:

    I assume that the error is happening on lines 25 and 26. The way you're getting the date is wrong. To get the current time, you need only to use the method time(), this will return a timestamp that can be used in the date() function. To get a time in the future you have a few options. You can either get the current time with time() and add the number of seconds until the future date (in your case, 12 months in advance, so it would be 60 * 60 * 24 * 365 = 31536000), or use the strtotime() function, which has the following syntax:

    $future = strtotime("+1 year");

    or

    $future = strtotime("+12 months");

    Or basically any combination that would evaluate to 1 year in the future, so 1 year, 12 months, 52 weeks, or 365 days. This will also return a timestamp for the future date. I recommend strtotime().

    I hope I've helped, please let me know if you need something explained and I'll do my best.

    Comment

    • tutusaint
      New Member
      • Sep 2010
      • 18

      #3
      Thanks.
      Please give me a beta explanation.
      I need to capture the current date to the database.
      And also add 12 months to it and save the result to the database in Y-m-d format

      Comment

      • HaLo2FrEeEk
        Contributor
        • Feb 2007
        • 404

        #4
        I not only gave you the exact explanation as to what you needed to do, I gave you the CODE for what you need. Storing a date in a database in "y-m-d" format is a very poor and inefficient use of database space. A timestamp is a universal measurement of time that (for now) uses a 32-bit integer to keep track of the number of seconds that have passed since the unix epoch, which is 1/1/1970 at 12:00:00 am. Since this number is universal, it's supported in nearly all programming languages, including PHP.

        I TOLD you what you needed to do and I GAVE you the code to do it, now do a little work yourself and figure it out. We're not here to do things for you, we're here to help you learn how to do them yourself.

        Seriously, this is frustrating. Go back, read my reply, pay attention, and think about exactly what I said.

        Return current Unix timestamp

        Comment

        Working...