Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6337113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:11:25+00:00 2026-05-24T19:11:25+00:00

I get the error: Column ‘Time’ cannot be null when using the query below,

  • 0

I get the error: Column ‘Time’ cannot be null when using the query below, it works fine the first time when there is no duplicate but then when trying to update again I get the error: Column ‘Time’ cannot be null

    mysql_query("
    INSERT INTO
    $table(Username, Time, Videos, Credits)
    VALUES
    ('$user', '$time', '$videos', '$credits')
    ON DUPLICATE KEY UPDATE
    Time=Time+INTERVAL $time SECOND
    Videos=Videos+'$videos',
    Credits=Credits+'$credits'
    ",
    $conn
    );

Hope you can spot my error as I am new to this, thanks!

Here is some more of my code:

$conn = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
mysql_select_db(DB_NAME, $conn);

// Error checking
if(!$conn) {
    die('Could not connect ' . mysql_error());
}

// Localize the GET variables
$user   = isset($_GET['username']) ? $_GET['username'] : "";
$time   = isset($_GET['time']) ? $_GET['time']  : "";
$videos  = isset($_GET['videos']) ? $_GET['videos'] : "";
$credits  = isset($_GET['credits']) ? $_GET['credits'] : "";

// Protect against sql injections
$user  = mysql_real_escape_string($user);
$time  = mysql_real_escape_string($time);
$videos = mysql_real_escape_string($videos);
    $credits = mysql_real_escape_string($credits);
    $secret = mysql_real_escape_string($secret);

// Insert
$retval = mysql_query("
     INSERT INTO
     $table(Username, Time, Videos, Credits)
     VALUES
     ('$user', '$time', '$videos', '$credits')
     ON DUPLICATE KEY UPDATE
     Time = DATE_ADD(IFNULL(Time,now()),INTERVAL '$time' SECOND),
     Videos = Videos+'$videos',
     Credits = Credits+'$credits'
     ",
     $conn
     );
    // End Query


if($retval) {
    echo "Success! Updated $user with Time: $time - Videos: $videos - Credits: $credits";
} else {
    echo "<b>ERROR:</b><br>" . mysql_error();
}

mysql_close($conn);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T19:11:26+00:00Added an answer on May 24, 2026 at 7:11 pm

    It should be:

    mysql_query("
    INSERT INTO
    $table(Username, `Time`, Videos, Credits)
    VALUES
    ('$user', '$time', '$videos', '$credits')
    ON DUPLICATE KEY UPDATE
    Time = DATE_ADD(IFNULL(`Time`,now()),INTERVAL '$time' SECOND)
    ,Videos = Videos+'$videos'
    ,Credits = Credits+'$credits'
    ",
    $conn
    );
    

    Don’t forget to put single quotes around all injected variables, otherwise mysql_real_escape_string will not protect you.

    See:
    http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When i use alias for column i get error. Without alias everytinig works good.
I get this error: Can't locate Foo.pm in @INC Is there an easier way
I get an error when I compile this code: using System; public struct Vector2
(int) faultsGroup is 0 or 1 but i always get this error: Column 'FaultGroup'
I'm using Symfony for the first time, and on a project requiring the front
I get the error Unknown column 'm.id' in 'on clause' all my tables have
I'm trying join in Rails 3 for the first time, and can't get the
By using g:datePicker on java.sql.Time object that refers to a TIME legacy DB column
I get the Error: Column count doesn't match value count at row 1. But
Previously I selected everything by putting a null, but i get an error complaining

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.