0

I've searched and tried a couple of different ways but I always get a 0000-00-00 00:00:00

Here's my page:

<?php

require_once "../../maincore.php";

require_once THEMES."templates/header.php";



$earnedpoints = false; 

$account = $_GET['account']; 

$account = mysql_real_escape_string($account); 



if ($account == "") { 

    echo 'Enter an account name!'; 

    exit(); 

} 



$ip = $_SERVER['REMOTE_ADDR']; 

$time = time(); 



$query = mysql_query("SELECT *, SUM(`times`) as amount FROM votingrecords WHERE account='$account' OR ip='$ip'"); 

$lasttime = mysql_fetch_array($query); 

$amount = $lasttime['amount']; 

$insertnew = false;     

if ($amount == "") { 

    $insertnew = true; 

} 

$timecalc = $time - $lasttime['date'];



if (!$insertnew) { 

    if ($timecalc < 43200) {  

    require_once THEMES."templates/header.php";

    add_to_title(" - Vote");

    opentable("Error");

    echo "<table class='tbl-border' width='100%' cellspacing='1' cellpadding='5'><td class='tbl2'>";

        echo ' Hello '. $account .' you have already voted with this account ('. $account .') or IP ('. $ip .') in the last 12 hours!'; 

        echo ' Last voted on: '. date('Y-m-d H:i:s', $lasttime['date']) .''; 

        echo '<html>'; 

        echo '<head>'; 

    echo '<meta HTTP-EQUIV="REFRESH" content="10; url=\vote.php?account=' . $_GET['account'] . '">'; 

        echo '</head>'; 

        echo '<body>'; 

        echo '<br /><br /><center>You will be redirected to the main website in 10 seconds.</center>'; 

        echo '</body>'; 

        echo '</html>'; 

    echo "</td></table>";

    closetable();

    require_once THEMES."templates/footer.php";

        exit(); 

    } else {                 

        $update = mysql_query("UPDATE votingrecords SET account='$account', date='NOW()', times=times+1 WHERE ip='$ip'");

            if (!$update) { 

                $message  = 'Invalid query: ' . mysql_error() . "\n"; 

                $message .= 'Whole query: ' . $update; 

                die($message); 

            } else { 

                $earnedpoints = true; 

            } 

        } 

} else { 

    $success = mysql_query("INSERT INTO votingrecords (`account`, `ip`, `date`, `times`) VALUES ('$account', '$ip', 'NOW()', 1)"); 

    if (!$success) { 

            $message  = 'Invalid query: ' . mysql_error() . "\n"; 

            $message .= 'Whole query: ' . $success; 

            die($message); 

    } else { 

        $earnedpoints = true; 

    } 

}

if ($earnedpoints) { 

    $points = mysql_query("UPDATE user SET votingpoints = votingpoints + 1 WHERE login='$account'");                

    if (!$points) { 



            $message  = 'Invalid query: ' . mysql_error() . "\n"; 

            $message .= 'Whole query: ' . $query; 

            die($message); 

    } 

    mysql_close(); 

    echo '<html>'; 

    echo '<head>'; 

    echo '<meta HTTP-EQUIV="REFRESH" content="0; url=vote here">'; 

    echo '</head>'; 

    echo '</html>'; 

} else { 

    echo 'There was an error processing your request.'; 

    exit(); 

} 



require_once THEMES."templates/footer.php";

?>

That solved my problem with it not inserting the date, that works fine now!! thanks alot! I thought it would solve my issue with it not keeping track of when a user votes so they can only vote each 12 hours.It still lets people vote over and over again >.<

Is there anyway to bump this? Lmao.. Still could use some help

1
  • 5
    You should post the relevant code and var_dump()'s of the relevant variables here. Commented Feb 26, 2014 at 20:24

2 Answers 2

4

Don't put NOW() inside of single quotes...

Sign up to request clarification or add additional context in comments.

Comments

1

I just checked the code and you have 'NOW()' in the insert take out quotes and use just now().

'NOW()' will be treated as string and while adding to mysql datetime field its invalid and thus will have 0000-00.....

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.