PHP School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a PHP Expert!

Join 300,439 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,488 people online right now. Registration is fast and FREE... Join Now!




mktime() error

 

mktime() error

Decypher

2 Jul, 2009 - 08:11 AM
Post #1

D.I.C Regular
***

Joined: 28 Jun, 2008
Posts: 370



Thanked: 2 times
My Contributions
Not sure what's wrong with it

CODE

<?php
function revertjailtime($str) {
        list($date, $time) = explode(' ', $str);
        list($year, $month, $day) = explode('-', $date);
        list($hour, $minute, $second) = explode(':', $time);

        $timestamp = mktime($hour, $minute, $second, $month, $day, $year);
        return $timestamp;
    }
    $query = "SELECT username FROM login WHERE id='".$_SESSION["userid"]."'";
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result)){
    
    $username = $row['username'];
    
    $q = "SELECT time, length FROM jail WHERE username='".$username."'";
    $r = mysql_query($q);
    $v = mysql_fetch_array($r);
    $length = $v['length'];
    $lastActive = revertjailtime($v['time']);
    if ($lastActive + $length - time() > 0) {
    } else {
        $delete="DELETE FROM jail WHERE username = '".$username."'";
        mysql_query($delete);
        
    }}
?>

<table width=50% border="1" bordercolor="#000000">
<tr><td align="center" bgcolor="#666666" colspan="3">Jail</td></tr>
<tr><td align="center" colspan="3"><img src="" alt="Jail"></td></tr>
<tr bgcolor="#666666"><td>Name</td><td>Time</td><td>Bust?</td></tr>
<?
$jailq ="SELECT * FROM jail";
$jailr = mysql_query($jailq);
while ($row = mysql_fetch_array($jailr)){
    $username = $row['username'];
    $length= $row['length'];
    $time = $row['time'];

echo'
<tr><td>'.$username.'</td><td>';
$lastActive = revertjailtime($time);
echo $lastActive + $length - time();
echo'
</td><td>Bust Out</td></tr>'; }
?>


User is offlineProfile CardPM
+Quote Post


RudiVisser

RE: Mktime() Error

2 Jul, 2009 - 09:28 AM
Post #2

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,872



Thanked: 137 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
What's the actual error??

Below are the functions I use for MySQL DateTime parsing:
CODE
public function CreateTimestamp($DateTime) {
        $Split = explode(" ", $DateTime);
        $Date = explode("-", $Split[0]);
        $Time = explode(":", $Split[1]);
        return mktime($Time[0], $Time[1], $Time[2], $Date[1], $Date[2], $Date[0]);
    }
    public function CreateFriendlyDate($timestamp) {
        if(date("W") == date("W", $timestamp)) {
            if(date("j") == date("j", $timestamp))
                return date("\\T\\o\\d\\a\\y \\a\\t H:i", $timestamp);
            return date("l \\a\\t H:i", $timestamp);
        } else {
            return date("jS M \\a\\t H:i", $timestamp);
        }
    }

User is offlineProfile CardPM
+Quote Post

Decypher

RE: Mktime() Error

2 Jul, 2009 - 10:12 AM
Post #3

D.I.C Regular
***

Joined: 28 Jun, 2008
Posts: 370



Thanked: 2 times
My Contributions
sorry thought I put the error up:

Warning: mktime() expects parameter 1 to be long, string given in /home/a6490674/public_html/Mafia/jail.php on line 20
User is offlineProfile CardPM
+Quote Post

Decypher

RE: Mktime() Error

2 Jul, 2009 - 10:32 AM
Post #4

D.I.C Regular
***

Joined: 28 Jun, 2008
Posts: 370



Thanked: 2 times
My Contributions
I only get the error way there's no info in the table...

But at times there will be no data table


User is offlineProfile CardPM
+Quote Post

RudiVisser

RE: Mktime() Error

2 Jul, 2009 - 10:33 AM
Post #5

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,872



Thanked: 137 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
If there's no data in the table, why are you calling a function that will work with the data?
User is offlineProfile CardPM
+Quote Post

CTphpnwb

RE: Mktime() Error

2 Jul, 2009 - 10:35 AM
Post #6

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,065



Thanked: 151 times
Dream Kudos: 100
Expert In: PHP

My Contributions
You could force type:
CODE
        return mktime((int)$Time[0], (int)$Time[1], (int)$Time[2], (int)$Date[1], (int)$Date[2],(int)$Date[0]);

User is offlineProfile CardPM
+Quote Post

ShaneK

RE: Mktime() Error

2 Jul, 2009 - 10:47 AM
Post #7

require_once("brain.php"); //Fatal error :/
Group Icon

Joined: 10 May, 2009
Posts: 699



Thanked: 47 times
Dream Kudos: 75
Expert In: PHP, MySQL

My Contributions
Or you could just check if it's null/empty, and if it is then return something else...
I fail to see the point in using a function on something that you don't need to...

Yours,
Shane~

This post has been edited by ShaneK: 2 Jul, 2009 - 10:48 AM
User is offlineProfile CardPM
+Quote Post

Decypher

RE: Mktime() Error

2 Jul, 2009 - 10:53 AM
Post #8

D.I.C Regular
***

Joined: 28 Jun, 2008
Posts: 370



Thanked: 2 times
My Contributions
because it's a check to see if the play is still in jail or not.

it does it so it works out if the player still has time left in the jail and if so does nothing for the jail page but if time is up deletes it from the jail table.

I get the same error on other pages where it needs to check if players are in jail, incase they try and do something when they're not allowed while in jail

QUOTE(ShaneK @ 2 Jul, 2009 - 10:47 AM) *

Or you could just check if it's null/empty, and if it is then return something else...
I fail to see the point in using a function on something that you don't need to...

Yours,
Shane~


cheers shane didn't think about using an if statement to actaully check if there is any data in the table before using the function smile.gif
User is offlineProfile CardPM
+Quote Post

CTphpnwb

RE: Mktime() Error

2 Jul, 2009 - 10:53 AM
Post #9

D.I.C Lover
Group Icon

Joined: 8 Aug, 2008
Posts: 2,065



Thanked: 151 times
Dream Kudos: 100
Expert In: PHP

My Contributions
Sometimes it's just easier to call the function, then disregard the results if it comes back with the wrong information, in this case: 943938000
wink2.gif
User is offlineProfile CardPM
+Quote Post

Decypher

RE: Mktime() Error

2 Jul, 2009 - 11:15 AM
Post #10

D.I.C Regular
***

Joined: 28 Jun, 2008
Posts: 370



Thanked: 2 times
My Contributions
well after adding a if statement the error goes away cheers for all the help smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:07AM

Live PHP Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month