How to add a column to the sql insert server side?

How to add a column to the sql insert server side?

webvisionwebvision Posts: 10Questions: 7Answers: 0

The record is inserting just fine… but the c_id (customer id) field, which is not shown to the customer in either the form or the DataTable, is not present. I wish to add it to the sql insert.

I'm currently passing the value via the url as such:

$(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
        ajax: "workorder.php?c_id=1,

I could use the session to do this as well, but for testing I was attempting to use _POST.

Now I wish to include c_id in the insert… this is where I get lost.

I tried writing to _POST['c_id']=1, which remains null regardless.

What method is used to add to the sql insert?

I'm not sure if this is the best method for adding variables to the insert… but I know it will work, once I know how to write to the sql insert statement.

Answers

  • webvisionwebvision Posts: 10Questions: 7Answers: 0

    I found this and it worked like a charm:

    if ( isset($_POST['action']) && ( $_POST['action'] === 'create' || $_POST['action'] === 'edit' ) ) {   
    $_POST['data']['c_id'] = htmlspecialchars($_GET["cid"]);
    }
    

    I also found the syntax for the where clause:

    Field::inst( 'workorder_date' )
        ->validator( 'Validate::dateFormat', array(
            "format"  => Format::DATE_ISO_8601,
            "message" => "Please enter a date in the format yyyy-mm-dd"
        ) )
        ->getFormatter( 'Format::date_sql_to_format', Format::DATE_ISO_8601 )
        ->setFormatter( 'Format::date_format_to_sql', Format::DATE_ISO_8601 )
    )->where( $key = "c_id", $value = htmlspecialchars($_GET["cid"]), $op = '=' )
    ->process( $_POST )
    ->json();
    
This discussion has been closed.