Page 2 of 5

Re: PHP Question

Posted: Thu Aug 13, 2009 7:34 am
by Jackolantern
I am fairly new with PHP, but isn't there just some function or some easy way to convert the "seconds since 1/1/1970"-style dates to a more traditional read-out? Most other languages I have worked with have a function for changing them easily, because the seconds readout is just not useful to humans.

Re: PHP Question

Posted: Thu Aug 13, 2009 7:44 am
by jpoisson
The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer). However, before PHP 5.1.0 this range was limited from 01-01-1970 to 19-01-2038 on some systems (e.g. Windows).

http://ca3.php.net/manual/en/function.date.php

Re: PHP Question

Posted: Thu Aug 13, 2009 8:20 am
by SpiritWebb
jpoisson wrote:I am not sure if this will help you but I have been working on my own date time functions, no suprise there. I use varchar(25) for my coloum settings. Why would i do this well in your authentication page you can creat a variable
called $datetime and the row can be called what ever.

Code: Select all

$datetime = date("d/m/y h:i:s"); //create date time
the date() function will grab the latest time and I am formatting it in a way so it is readable instead of a bunch of random numbers.

xx/xx/xx/ xx:xx:xx will be the out put for that variable.

then you update the column where you are storing the time with this variable. 
I tried this, and cannot seem to get it too work. In my players field, I have a column called, "lastlogin, VARCHAR(25)"

I placed the code in the logout.php file, between session start and session destroy. As I want it too store the current date when logging out. That way next time they log in, they will see the date they logged out the last time.

Re: PHP Question

Posted: Thu Aug 13, 2009 8:29 am
by jpoisson
what is your query statement saying?

Code: Select all

$datetime=date("d/m/y h:i:s"); //create date time

$sql="INSERT INTO tablename (lastlogin)VALUES('$datetime')";
$result=mysql_query($sql);

the resulting code should work. as long as you place your tables name where it says tablename

Re: PHP Question

Posted: Thu Aug 13, 2009 8:49 am
by SpiritWebb
jpoisson wrote:what is your query statement saying?

Code: Select all

$datetime=date("d/m/y h:i:s"); //create date time

$sql="INSERT INTO tablename (lastlogin)VALUES('$datetime')";
$result=mysql_query($sql);

the resulting code should work. as long as you place your tables name where it says tablename
Its not giving an error...its not displaying the date in the database under lastlogin.

Here is my setup with your code (logout.php)

Code: Select all

<link href="style.css" rel="stylesheet" type="text/css" />
<STYLE type="text/css">
 <!--
 BODY { background-image:url(logoutFinish.png);
               background-repeat:no-repeat;
               background-position:center;
               background-attachment:fixed }
 -->
</STYLE>

<body bgcolor="black">
<body text="white">
<div id="return">
    <?php
    session_start();
    $datetime=date("d/m/y h:i:s"); //create date time

$SQL="INSERT INTO players (lastlogin) VALUES ('$datetime')";
$result=mysql_query($SQL);
  
  session_destroy();

     ?>
   </div>

Re: PHP Question

Posted: Thu Aug 13, 2009 1:19 pm
by hallsofvallhalla
what are you using varchar? There is a data field called date made specifically for this.

Re: PHP Question

Posted: Thu Aug 13, 2009 6:52 pm
by SpiritWebb
hallsofvallhalla wrote:what are you using varchar? There is a data field called date made specifically for this.
I seen curdate, but its a function, and it dont change, unless you have to set it up the first time you set up the field, in which case, I don't know how to setup the date function.

Re: PHP Question

Posted: Thu Aug 13, 2009 7:09 pm
by jpoisson
Umm, firstly you start_session is suppose to be placed at the top of every document before any code is to be written.

@ halls I use var char because I have had some poor instances with the mysql date variables. so it is a personal choice.

no back to your code what errors are you getting? for any method you try please post you error messages because this will allow us to understand what is actually going wrong.

Re: PHP Question

Posted: Thu Aug 13, 2009 7:58 pm
by SpiritWebb
jpoisson wrote:Umm, firstly you start_session is suppose to be placed at the top of every document before any code is to be written.

@ halls I use var char because I have had some poor instances with the mysql date variables. so it is a personal choice.

no back to your code what errors are you getting? for any method you try please post you error messages because this will allow us to understand what is actually going wrong.
Where the session_start() is located, is placed in the spot that Halls tells us in the tut videos. (The top part is for the background, and I don't seem to be having any issues with it, until now.) And there isn't anything between session_start() or session_destroy() in his video. I wanted to add the date save function in between these fields, so the date will not update until next logout. I am NOT getting any errors, it goes through just fine, but just doesn't place the date into the lastlogin field.

I tried placing the session_start() at the very top, but it still does the same thing regardless. It logs out just fine, but doesn't place the date into the field in MySql.

Re: PHP Question

Posted: Fri Aug 14, 2009 7:28 am
by jpoisson

Code: Select all

$result=mysql_query($SQL)or die('_'.mysql_error());   
try changing you query statement to this and tell us what it reports, because it sounds like their is no connection to your DB/Server