Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2007
    Location
    Bronx, New York, United States
    Posts
    521
    Plugin Contributions
    3

    Default How to insert a NULL value when using zen_db_perform() ?

    I'm currently trying to write my own product type for ZenCart 1.5. One of the fields on the collect_info page is supposed to enter a BLANK (null) value into the table. However, on the loading of the page, I noticed that instead of entering a null value, the script is inserting a value of zero (0). Does anyone know how I should I be doing the insert to make sure the NULL VALUE is inserted?

    Here is the insert statement as in my update_product.php:

    PHP Code:
          //// INSERT PRODUCT-TYPE-SPECIFIC *INSERTS* HERE //////
          
    $cfv_data_array = array('products_id' => $products_id,
                                  
    'grade' => zen_db_prepare_input($_POST['grade']),
                                  
    'nation_id' => zen_db_prepare_input($_POST['nation_id']),                              
                                  
    'clan_id' => zen_db_prepare_input($_POST['clan_id']),
                                  
    'race' => zen_db_prepare_input($_POST['race']),
                                  
    'rarity_id' => zen_db_prepare_input($_POST['rarity']),
                                  
    'trigger_id' => zen_db_prepare_input($_POST['trigger_id']),
                                  
    'skill_id' => zen_db_prepare_input($_POST['skill_id']),
                                  
    'power' => zen_db_prepare_input($_POST['power']),
                                  
    'shield' => zen_db_prepare_input($_POST['shield']),
                                  
    'critical' => zen_db_prepare_input($_POST['critical']),
                                  
    'flavor_text' => zen_db_prepare_input($_POST['flavor_text'])  
                                );            
    zen_db_perform(TABLE_CFV_CARDS$cfv_data_array);
          
    ////    *END OF PRODUCT-TYPE-SPECIFIC INSERTS* //////// 

  2. #2
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: How to insert a NULL value when using zen_db_perform() ?

    If I remember correctly you just use 'null' (yes as a string) passed in your data_array.

    So you will need something like: => (isset($_POST['flavor_text']) ? zen_db_prepare_input($_POST['flavor_text']) : 'null')
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  3. #3
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,896
    Blog Entries
    2
    Plugin Contributions
    2

    Default Re: How to insert a NULL value when using zen_db_perform() ?

    Hi,

    its a little difficult to give a generic answer as there is not enough information in your post.

    I'm going to assume the following.

    1) you definitley want a mysql NULL value inserted
    2) this is for one of the integer type fields e.g. trigger_id
    3) that this is set in the POST array as a blank value

    So, in the current code you have

    'trigger_id' => zen_db_prepare_input($_POST['trigger_id']),

    try changing that to

    'trigger_id' => ($_POST['trigger_id'] != "") ? zen_db_prepare_input($_POST['trigger_id']) : 'null',


    hth

 

 

Similar Threads

  1. Replies: 43
    Last Post: 21 Jan 2018, 05:55 PM
  2. Replies: 7
    Last Post: 4 May 2016, 01:59 AM
  3. v139h Bumped to admin home page when using value manager
    By robbin21973 in forum Setting Up Categories, Products, Attributes
    Replies: 2
    Last Post: 16 Jul 2012, 04:39 AM
  4. Replies: 11
    Last Post: 15 Jan 2010, 04:44 PM
  5. Mysql 5 strict mode no null value for manufacturer id
    By jiffy in forum General Questions
    Replies: 5
    Last Post: 2 Feb 2008, 12:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR