PHP Question
- Jackolantern
- Posts: 10891
- Joined: Wed Jul 01, 2009 11:00 pm
Re: PHP Question
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.
The indelible lord of tl;dr
Re: PHP Question
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
http://ca3.php.net/manual/en/function.date.php
Laguages:
PHP, MYSQL, (X)HTML, HTML5, JQuery, CSS 3.0,
C, C#, C++, Python, Pascal, Perl, Ruby, Turing
Software:
Adobe MC CS4, Visual Studio 2008, Notepad++,
NetBeans IDE, WAMPSERVER
Browsers:
Internet Explorer, Firefox, Opera, Safari, Chrome
(Always have latest patches for browsers.)
Free time:
...
PHP, MYSQL, (X)HTML, HTML5, JQuery, CSS 3.0,
C, C#, C++, Python, Pascal, Perl, Ruby, Turing
Software:
Adobe MC CS4, Visual Studio 2008, Notepad++,
NetBeans IDE, WAMPSERVER
Browsers:
Internet Explorer, Firefox, Opera, Safari, Chrome
(Always have latest patches for browsers.)
Free time:
...
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: PHP Question
I tried this, and cannot seem to get it too work. In my players field, I have a column called, "lastlogin, VARCHAR(25)"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 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
what is your query statement saying?
the resulting code should work. as long as you place your tables name where it says tablename
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);
Laguages:
PHP, MYSQL, (X)HTML, HTML5, JQuery, CSS 3.0,
C, C#, C++, Python, Pascal, Perl, Ruby, Turing
Software:
Adobe MC CS4, Visual Studio 2008, Notepad++,
NetBeans IDE, WAMPSERVER
Browsers:
Internet Explorer, Firefox, Opera, Safari, Chrome
(Always have latest patches for browsers.)
Free time:
...
PHP, MYSQL, (X)HTML, HTML5, JQuery, CSS 3.0,
C, C#, C++, Python, Pascal, Perl, Ruby, Turing
Software:
Adobe MC CS4, Visual Studio 2008, Notepad++,
NetBeans IDE, WAMPSERVER
Browsers:
Internet Explorer, Firefox, Opera, Safari, Chrome
(Always have latest patches for browsers.)
Free time:
...
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: PHP Question
Its not giving an error...its not displaying the date in the database under lastlogin.jpoisson wrote:what is your query statement saying?
the resulting code should work. as long as you place your tables name where it says tablenameCode: Select all
$datetime=date("d/m/y h:i:s"); //create date time $sql="INSERT INTO tablename (lastlogin)VALUES('$datetime')"; $result=mysql_query($sql);
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>
- hallsofvallhalla
- Site Admin
- Posts: 12023
- Joined: Wed Apr 22, 2009 11:29 pm
Re: PHP Question
what are you using varchar? There is a data field called date made specifically for this.
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: PHP Question
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.hallsofvallhalla wrote:what are you using varchar? There is a data field called date made specifically for this.
Re: PHP Question
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.
@ 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.
Laguages:
PHP, MYSQL, (X)HTML, HTML5, JQuery, CSS 3.0,
C, C#, C++, Python, Pascal, Perl, Ruby, Turing
Software:
Adobe MC CS4, Visual Studio 2008, Notepad++,
NetBeans IDE, WAMPSERVER
Browsers:
Internet Explorer, Firefox, Opera, Safari, Chrome
(Always have latest patches for browsers.)
Free time:
...
PHP, MYSQL, (X)HTML, HTML5, JQuery, CSS 3.0,
C, C#, C++, Python, Pascal, Perl, Ruby, Turing
Software:
Adobe MC CS4, Visual Studio 2008, Notepad++,
NetBeans IDE, WAMPSERVER
Browsers:
Internet Explorer, Firefox, Opera, Safari, Chrome
(Always have latest patches for browsers.)
Free time:
...
- SpiritWebb
- Posts: 3107
- Joined: Sun Jul 12, 2009 11:25 pm
Re: PHP Question
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.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.
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
Code: Select all
$result=mysql_query($SQL)or die('_'.mysql_error());
Laguages:
PHP, MYSQL, (X)HTML, HTML5, JQuery, CSS 3.0,
C, C#, C++, Python, Pascal, Perl, Ruby, Turing
Software:
Adobe MC CS4, Visual Studio 2008, Notepad++,
NetBeans IDE, WAMPSERVER
Browsers:
Internet Explorer, Firefox, Opera, Safari, Chrome
(Always have latest patches for browsers.)
Free time:
...
PHP, MYSQL, (X)HTML, HTML5, JQuery, CSS 3.0,
C, C#, C++, Python, Pascal, Perl, Ruby, Turing
Software:
Adobe MC CS4, Visual Studio 2008, Notepad++,
NetBeans IDE, WAMPSERVER
Browsers:
Internet Explorer, Firefox, Opera, Safari, Chrome
(Always have latest patches for browsers.)
Free time:
...