A new record is not updated immediately in the table

A new record is not updated immediately in the table

chagoldchagold Posts: 9Questions: 4Answers: 0
edited September 2019 in Free community support

When I create a new record (using a form), the record is created in a database, but it does not appear immediately on the table
(I only see it when I refresh the page)

When I create a new record (using a form), the record is created in a database, but it does not appear immediately on the table
(I only see it when I refresh the page)

The server code is

<?php

include( "lib/DataTables.php" );

use
    DataTables\Editor,
    DataTables\Editor\Field,
    DataTables\Editor\Format,
    DataTables\Editor\Mjoin,
    DataTables\Editor\Options,
    DataTables\Editor\Upload,
    DataTables\Editor\Validate,
    DataTables\Editor\ValidateOptions;

// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'business_owner')


    ->debug( true )
    ->fields(
        Field::inst( 'id' ),
        Field::inst( 'business_owner' )
        ->validator( Validate::notEmpty( ValidateOptions::inst()
            ->message( 'A first name is required' ) 
        ) ),
        Field::inst( 'job_id' )
            ->validator( Validate::notEmpty( ValidateOptions::inst()
                ->message( 'A last name is required' )  
            ) ),
        Field::inst( 'sub_jobs' )
            ->validator( Validate::notEmpty( ValidateOptions::inst()
                ->message( 'A last name is required' )  
            ) ),
        Field::inst( 'area' )
            ->validator( Validate::dbValues() ),
        Field::inst( 'city' ),
        Field::inst( 'genedr' ),
        Field::inst( 'hot_job_or_not' )
            ->setFormatter( Format::ifEmpty(null) ),
        
        Field::inst( 'date' )
            ->validator( Validate::dateFormat( 'd/m/Y' ) )
            ->getFormatter( Format::dateSqlToFormat( 'd/m/Y' ) )
            ->setFormatter( Format::dateFormatToSql('d/m/Y' ) ),
            



            Field::inst( 'source' ),
            Field::inst( 'contact_person' ),
            Field::inst( 'city_location' ),
            Field::inst( 'scope' ),
            Field::inst( 'email' ),
            Field::inst( 'name_rep' ),
            Field::inst( 'job_info' ),
            Field::inst( 'ID_number' ),
            Field::inst( 'job_sub_id' ),
            Field::inst( 'publish_on_others' ),
            Field::inst( 'job_phone' ),
            Field::inst( 'job_fax' ),
            Field::inst( 'job_email' ),
            Field::inst( 'bo_Name' ),
            Field::inst( 'phone' ),
            Field::inst( 'Mobile' ),
            Field::inst( 'adress' ),
            Field::inst( 'u_name' ),
            Field::inst( 'u_password' ),

            Field::inst( 'credit_owner_full_name' ),
            Field::inst( 'credit_type' ),
            Field::inst( 'credit_num' ),
            Field::inst( 'cvv' ),

            
            Field::inst( 'expire' ),
            Field::inst( 'phone_to_credit_copmany' ),
            Field::inst( 'comment' ),


            Field::inst( 'owner_contact_person' )           
    )
    
    ->process( $_POST )
    ->json();
?>

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,112Questions: 1Answers: 2,583
    edited September 2019

    Hi @chagold ,

    It does that when the server response isn't returning the expected format. Please can you post what the server returns,

    Cheers,

    Colin

  • chagoldchagold Posts: 9Questions: 4Answers: 0
    edited September 2019
    {
        "data": [],
        "debug": [{
            "query": "INSERT INTO  `business_owner`  ( `id`, `business_owner`, `genedr`, `hot_job_or_not`, `date`, `source`, `contact_person`, `email`, `name_rep`, `job_info`, `ID_number`, `job_phone`, `job_fax`, `job_email`, `bo_Name`, `Mobile`, `adress`, `approved_by_karyera`, `u_name`, `u_password`, `credit_owner_full_name`, `credit_type`, `credit_num`, `cvv`, `expire`, `phone_to_credit_copmany`, `comment`, `owner_contact_person` ) VALUES (  :id,  :business_owner,  :genedr,  :hot_job_or_not,  :date,  :source,  :contact_person,  :email,  :name_rep,  :job_info,  :ID_number,  :job_phone,  :job_fax,  :job_email,  :bo_Name,  :Mobile,  :adress,  :approved_by_karyera,  :u_name,  :u_password,  :credit_owner_full_name,  :credit_type,  :credit_num,  :cvv,  :expire,  :phone_to_credit_copmany,  :comment,  :owner_contact_person )",
            "bindings": [{
                "name": ":id",
                "value": "",
                "type": null
            }, {
                "name": ":business_owner",
                "value": "\u05d3\u05d2\u05db\u05d3",
                "type": null
            }, {
                "name": ":genedr",
                "value": "1",
                "type": null
            }, {
                "name": ":hot_job_or_not",
                "value": "0",
                "type": null
            }, {
                "name": ":date",
                "value": "2019-09-13",
                "type": null
            }, {
                "name": ":source",
                "value": "",
                "type": null
            }, {
                "name": ":contact_person",
                "value": "",
                "type": null
            }, {
                "name": ":email",
                "value": "",
                "type": null
            }, {
                "name": ":name_rep",
                "value": "\u05d0\u05dc\u05d9\u05d4\u05d5",
                "type": null
            }, {
                "name": ":job_info",
                "value": "",
                "type": null
            }, {
                "name": ":ID_number",
                "value": "",
                "type": null
            }, {
                "name": ":job_phone",
                "value": "",
                "type": null
            }, {
                "name": ":job_fax",
                "value": "",
                "type": null
            }, {
                "name": ":job_email",
                "value": "",
                "type": null
            }, {
                "name": ":bo_Name",
                "value": "",
                "type": null
            }, {
                "name": ":Mobile",
                "value": "",
                "type": null
            }, {
                "name": ":adress",
                "value": "",
                "type": null
            }, {
                "name": ":approved_by_karyera",
                "value": "0",
                "type": null
            }, {
                "name": ":u_name",
                "value": "",
                "type": null
            }, {
                "name": ":u_password",
                "value": "",
                "type": null
            }, {
                "name": ":credit_owner_full_name",
                "value": "",
                "type": null
            }, {
                "name": ":credit_type",
                "value": "",
                "type": null
            }, {
                "name": ":credit_num",
                "value": "",
                "type": null
            }, {
                "name": ":cvv",
                "value": "",
                "type": null
            }, {
                "name": ":expire",
                "value": "",
                "type": null
            }, {
                "name": ":phone_to_credit_copmany",
                "value": "",
                "type": null
            }, {
                "name": ":comment",
                "value": "",
                "type": null
            }, {
                "name": ":owner_contact_person",
                "value": "",
                "type": null
            }]
        }, {
            "query": "SELECT  `id` as 'id', `business_owner` as 'business_owner', `job_id` as 'job_id', `job_sub_id` as 'job_sub_id', `area` as 'area', `city` as 'city', `genedr` as 'genedr', `hot_job_or_not` as 'hot_job_or_not', `date` as 'date', `source` as 'source', `contact_person` as 'contact_person', `city_location` as 'city_location', `scope` as 'scope', `email` as 'email', `name_rep` as 'name_rep', `job_info` as 'job_info', `ID_number` as 'ID_number', `job_sub_id` as 'job_sub_id', `publish_on_others` as 'publish_on_others', `job_phone` as 'job_phone', `job_fax` as 'job_fax', `job_email` as 'job_email', `bo_Name` as 'bo_Name', `phone` as 'phone', `Mobile` as 'Mobile', `adress` as 'adress', `approved_by_karyera` as 'approved_by_karyera', `u_name` as 'u_name', `u_password` as 'u_password', `credit_owner_full_name` as 'credit_owner_full_name', `credit_type` as 'credit_type', `credit_num` as 'credit_num', `cvv` as 'cvv', `expire` as 'expire', `phone_to_credit_copmany` as 'phone_to_credit_copmany', `comment` as 'comment', `owner_contact_person` as 'owner_contact_person' FROM  `business_owner` WHERE `id` = :where_0 ",
            "bindings": [{
                "name": ":where_0",
                "value": "",
                "type": null
            }]
        }]
    }
    
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    "data": [],

    Which is why it isn't appearing in the table immediately. The debug (thanks for that) shows that the bound value of the id to fetch is an empty string, which in turn is why data is an empty array.

    In turn (again) you are setting id to be an empty string on the insert:

                "name": ":id",
                "value": "",
                "type": null
    

    I imagine that the database is overriding that, but the Editor libraries don't know that.

    What is id - is it an auto sequence? Can you just not insert into it? Field::inst( 'id' )->set(false)?

    Allan

  • chagoldchagold Posts: 9Questions: 4Answers: 0

    Thank you!!

This discussion has been closed.