HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Problem inserting blank Date to Database

I am trying to insert a null value into a date field in the database when a user does not fill out the form but instead i get a '' that is '{nothing}' value If i want the database to treat the '' value as null how would i do that?

I get the current error


  "Code": 256,

  "Exception": "Incorrect date value: '' for column 'EventCalendarDate' at row 1|Gdn_Database|Query|insert `GDN_Discussion` \n(`Body`, `CategoryID`, `InsertUserID`, `Name`, `Format`, `Announce`, `DateInserted`, `InsertIPAddress`, `DateLastComment`, `EventCalendarDate`) \nvalues (:Body, :CategoryID, :InsertUserID, :Name, :Format, :Announce, :DateInserted, :InsertIPAddress, :DateLastComment, :EventCalendarDate)",

  "Class": "Gdn_ErrorException",

  "StackTrace": "#0 [internal function]: gdn_ErrorHandler(256, 'Incorrect date ...', '/var/www/pokerf...', 421, Array)\n#1 /var/www/pokerforum.ca/library/database/class.database.php(421): trigger_error('Incorrect date ...', 256)\n#2 /var/www/pokerforum.ca/library/database/class.sqldriver.php(1707): Gdn_Database->query('insert `GDN_Dis...', Array, Array)\n#3 /var/www/pokerforum.ca/library/database/class.sqldriver.php(1133): Gdn_SQLDriver->query('insert `GDN_Dis...', 'insert')\n#4 /var/www/pokerforum.ca/applications/vanilla/models/class.discussionmodel.php(2171): Gdn_SQLDriver->insert('Discussion', Array)\n#5 /var/www/pokerforum.ca/applications/vanilla/controllers/class.postcontroller.php(323): DiscussionModel->save(Array)\n#6 /var/www/pokerforum.ca/library/core/class.dispatcher.php(872): PostController->discussion('test-2')\n#7 /var/www/pokerforum.ca/library/core/class.dispatcher.php(289): Gdn_Dispatcher->dispatchController(Object(Gdn_Request), Array)\n#8 /var/www/pokerforum.ca/index.php(29): Gdn_Dispatcher->dispatch()\n#9 {main}",

  "Data": {

    "isHomepage": false,

    "Category": {

      "CategoryID": 2,

      "ParentCategoryID": -1,

      "TreeLeft": 2,

      "TreeRight": 3,

      "Depth": 1,

      "CountCategories": 0,

      "CountDiscussions": 0,

      "CountAllDiscussions": 0,

      "CountComments": 0,

      "CountAllComments": 0,

      "LastCategoryID": 0,

      "DateMarkedRead": null,

      "AllowDiscussions": 1,

      "Archived": 0,

      "CanDelete": 1,

      "Name": "Test 2",

      "UrlCode": "test-2",

      "Description": "sdfgsdfg",

      "Sort": 2,

      "CssClass": "Category-test-2",

      "Photo": "",

      "PermissionCategoryID": -1,

      "PointsCategoryID": 0,

      "HideAllDiscussions": 0,

      "DisplayAs": "Discussions",

      "InsertUserID": 2,

      "UpdateUserID": 2,

      "DateInserted": "2020-03-22 16:45:40",

      "DateUpdated": "2020-03-22 16:45:40",

      "LastCommentID": null,

      "LastDiscussionID": null,

      "LastDateInserted": null,

      "AllowedDiscussionTypes": null,

      "DefaultDiscussionType": null,

            "Url": "http://pokerforum.main.nu/categories/test-2",

      "PhotoUrl": "",

      "PermsDiscussionsView": true,

      "PermsDiscussionsAdd": true,

      "PermsDiscussionsEdit": true,

      "PermsCommentsAdd": true


    "Title": "New Discussion",

    "Type": "Discussion"




  • Options

    NM on the submission validation it was checking to see if the User or the Category was not allowed (which it wasent) to have an EventCalendarDate and in this case you want to unset the variable and if it does not exist then the database will null out the field as that is the default value if nothing is presented. For some reason I just blanked out the variable incited of unsetting it

    so I change

    $args['FormPostValues']['EventCalendarDate'] = '';



Sign In or Register to comment.