Jump to content

[SOLVED] Error in Date Check


mattal999

Recommended Posts

I have this script which checks the date of the players last race:

 

<?php

include "connect.php";

$date = date("Y-m-d");

$player=$_SESSION['username'];

$playerstats1="SELECT * from dragusers WHERE username='$player'";

$playerstats2=mysql_query($playerstats1) or die ("Could not find player");

while($playerstats3=mysql_fetch_array($playerstats2))

{

$MySqlDate = $playerstats3[lastrace];

if($MySqlDate == '0000-00-00') {

header("location:gorace.php");

} else {

$date_array = explode("-",$MySqlDate);

$var_year = $date_array[0];

$var_month = $date_array[1];

$var_day = $date_array[2];

$donewtime = date("d-m-Y", mktime(0, 0, 0, $var_month, $var_day, $var_year));

if(strtotime($playerstats3[lastrace]) > time()) {

print "You can race again tommorow";

}

if(strtotime($playerstats3[lastrace]) < time()) {

$updateplayerstats="Update rpgusers set lastrace='0' where username='$playerstats3[username]'";

mysql_query($updateplayerstats) or die("<body bgcolor='3d3d3d'><font color='ffffff' size='1' face='verdana'>Could not update player stats");

print "You can now have 3 More Races";

}

if(strtotime($playerstats3[lastrace]) == time()) {

$updateplayerstats="Update rpgusers set lastrace='0' where username='$playerstats3[username]'";

mysql_query($updateplayerstats) or die("<body bgcolor='3d3d3d'><font color='ffffff' size='1' face='verdana'>Could not update player stats");

print "You can now have 3 More Races";

}

}

}

?>

 

and it it formatted 0000-00-00. When i run this i get a blank white page no matter what...

 

Help?

Link to comment
https://forums.phpfreaks.com/topic/71157-solved-error-in-date-check/
Share on other sites

Try adding some print statements throughout your code.  These can show you what the values of variables are.  They can also tell you if your script dies at some point.

 

Also try adding this at the start of your script:

 

ini_set('display_errors', 1);

First off, when i am looking for errors i find it very helpful if i format my code

 

<?php
include "connect.php";
$date = date("Y-m-d");
$player=$_SESSION['username'];
$playerstats1="SELECT * from dragusers WHERE username='$player'";
$playerstats2=mysql_query($playerstats1) or die ("Could not find player");

while($playerstats3=mysql_fetch_array($playerstats2)){
     $MySqlDate = $playerstats3[lastrace];

      if($MySqlDate == '0000-00-00') {

           header("location:gorace.php");

      } else {

            $date_array = explode("-",$MySqlDate);
            $var_year = $date_array[0];
            $var_month = $date_array[1];
            $var_day = $date_array[2];
            $donewtime = date("d-m-Y", mktime(0, 0, 0, $var_month, $var_day, $var_year));

            if(strtotime($playerstats3[lastrace]) > time()) {

                      print "You can race again tommorow";

               }

            if(strtotime($playerstats3[lastrace]) < time()) {

                    $updateplayerstats="Update rpgusers set lastrace='0' where username='$playerstats3[username]'";
                     mysql_query($updateplayerstats) or die("<body bgcolor='3d3d3d'><font color='ffffff' size='1' face='verdana'>Could not update player stats");

                      print "You can now have 3 More Races";

             }

              if(strtotime($playerstats3[lastrace]) == time()) {

                      $updateplayerstats="Update rpgusers set lastrace='0' where username='$playerstats3[username]'";
                       mysql_query($updateplayerstats) or die("<body bgcolor='3d3d3d'><font color='ffffff' size='1' face='verdana'>Could not update player stats");

                       print "You can now have 3 More Races";

                 }

         }

}

?>

 

and if I had to guess, you are making an infinite loop with the while statement.

 

also, i dont know a ton about arrays, but can you use words in them or does it have to be numbers

 

~d

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.