Adding many records using dropdown box PLEASE HELP!!

Discussion in 'PHP' started by NITRO23456, May 2, 2009.

  1. #1
    Hi

    I am trying to write an inventory program.

    The user fills in the details of incoming stock once and selects how many were received in that batch (ie the same type of stock) using a dropdown select box. I then want the same record to be added to the database that number of times (the number selected in the dropdown box).

    I cant get this working for the life of me. My code is below, but this only adds the record once rather than the number of times stated in the dropdown box.

    The dropdown box field is NUMBER RECEIVED IN BATCH the first field called ID is an autoincrement INT field.

    
    <?php
    
    
    // Before record added
    function BeforeAdd(&$values,&$message,$inline)
    {
    // Parameters:
    // $values - Array object. 
    // Each field on the Add form is represented as a 'Field name'-'Field value' pair
    
    
    //**********  Custom code  ************
    // put your custom code here
    
    for($i=1;$i<=$values["NUMBER_RECEIVED_IN_BATCH"];$i++)
    {
    mysql_query("Insert into STOCKCHECKER ('ID','SITE','DISCIPLINE','ITEM TYPE','BATCH/LOT NUMBER','EXPIRY DATE','NUMBER RECEIVED IN BATCH','RECEIVED BY','RECEIVED ON','PACKAGE INSERT CHECKED','USE COMMENCED BY','USE COMMENCED ON','TRANSFERRED BY','TRANSFERRED TO','SECOND SITE RECEIVED BY','NOTE/COMMENTS') VALUES ('".$i."','".$values["SITE"]."','".$values["DISCIPLINE"]."','".$values["ITEM_TYPE"]."','".$values["BATCH/LOT_NUMBER"]."','".$values["EXPIRY_DATE"]."','".$values["NUMBER_RECEIVED_IN_BATCH"]."','".$values["RECEIVED_BY"]."','".$values["RECEIVED_ON"]."','".$values["PACKAGE_INSERT_CHECKED"]."','".$values["USE_COMMENCED_BY"]."','".$values["USE_COMMENCED_ON"]."','".$values["TRANSFERRED_BY"]."','".$values["TRANSFERRED_TO"]."','".$values["SECOND_SITE_RECEIVED_BY"]."','".$values["NOTE/COMMENTS"]."')");
    }
    
    return true;
    
    // return true if you like to proceed with adding new record
    // return false otherwise 
    
    
    } // function BeforeAdd
    
    
    
    ?>
    
    Code (markup):

     
    NITRO23456, May 2, 2009 IP
  2. yz4now

    yz4now Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Have you check to make sure that this is not a MySQL query issue. Add or die(mysql_error()); to the end of your query. Then echo out the BeforeAdd() function, just to see what is going wrong.

    Hope that helps.
     
    yz4now, May 2, 2009 IP