Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.