PHP/MySQL help...
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: PHP/MySQL help...

  1. #1
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,697

    PHP/MySQL help...

    Hey gang-

    having some trouble with my script...

    everything 'seems' to be working fine (when I print out vars/data, it all is correct).. until I get to the part where I need to INSERT these multiple records into the database...

    Odd thing is, I am not getting any errors at all.. to even help me troubleshoot.



    goal/summary:
    scrape a directory for as many .txt files as I find...
    create array...

    using this array I loop through all file names.. and open up the file.. strip out each line, explode into an array.. ($allLinesArray)


    with my 'master' $allLinesArray.. I loop through it.. building a variable ($allRecords).. to be used in my MySQL INSERT command..

    everythings seems to work.. everything echos/prints fine... but nothing gets dumped to the database..? no feedback? no errors? no warnings?

    any suggestions? ideas?

    thanks!




    code:
    PHP Code:
    function insertRecords(){
        
        global 
    $allRecords$myDB$subDate$allLinesArray$result;
        
    //echo('INSERTING NEW RECORD<br><br>');
        //echo('TOTAL RECORDS: ' . count($paymentAmount) .'<br>');

        
    for($i=0$i count($allLinesArray); $i++) {
            
            
            if(
    $i){
                
    $allRecords .= ',';
            }        
            
            
    //echo("CHECK: " . $allLinesArray[$i][142] . "<br>");
            //echo("CHECK: " . $allLinesArray[$i][2] . "<br>");
            //echo("looping: " . $i);
            
            //** first index is ID# (auto-populated)        
            
    $allRecords .= "('','$allLinesArray[$i][1]','$allLinesArray[$i][2]','$allLinesArray[$i][3]','','','$allLinesArray[$i][4]','$allLinesArray[$i][5]','$allLinesArray[$i][6]','$allLinesArray[$i][7]','$allLinesArray[$i][8]','$allLinesArray[$i][9]','$allLinesArray[$i][10]','$allLinesArray[$i][11]','$allLinesArray[$i][12]','$allLinesArray[$i][13]','$allLinesArray[$i][14]','$allLinesArray[$i][15]','$allLinesArray[$i][16]','$allLinesArray[$i][17]','$allLinesArray[$i][18]','$allLinesArray[$i][19]','$allLinesArray[$i][20]','$allLinesArray[$i][51]','$allLinesArray[$i][52]','$allLinesArray[$i][53]','$allLinesArray[$i][54]','$allLinesArray[$i][55]','$allLinesArray[$i][56]','$allLinesArray[$i][57]','$allLinesArray[$i][58]','$allLinesArray[$i][59]','$allLinesArray[$i][60]','$allLinesArray[$i][61]','$allLinesArray[$i][62]','$allLinesArray[$i][63]','$allLinesArray[$i][64]','$allLinesArray[$i][65]','$allLinesArray[$i][66]','$allLinesArray[$i][67]','$allLinesArray[$i][140]','$allLinesArray[$i][141]','$allLinesArray[$i][142]','$allLinesArray[$i][143]','$allLinesArray[$i][144]','$allLinesArray[$i][145]','$allLinesArray[$i][146]','$allLinesArray[$i][147]','$allLinesArray[$i][148]','$allLinesArray[$i][149]','$allLinesArray[$i][150]','$allLinesArray[$i][151]','$allLinesArray[$i][152]','$allLinesArray[$i][153]','$allLinesArray[$i][154]','$allLinesArray[$i][155]','$allLinesArray[$i][156]','$allLinesArray[$i][157]','$allLinesArray[$i][158]','$allLinesArray[$i][159]','$allLinesArray[$i][160]','$allLinesArray[$i][161]','$allLinesArray[$i][162]','$allLinesArray[$i][163]','$allLinesArray[$i][164]','$allLinesArray[$i][165]','$allLinesArray[$i][166]','$allLinesArray[$i][167]','$allLinesArray[$i][168]','$allLinesArray[$i][169]','$allLinesArray[$i][170]','$allLinesArray[$i][171]','$allLinesArray[$i][172]','$allLinesArray[$i][173]','$allLinesArray[$i][174]','$allLinesArray[$i][175]','$allLinesArray[$i][176]','$allLinesArray[$i][177]','$allLinesArray[$i][178]','$allLinesArray[$i][179]','$allLinesArray[$i][180]','$allLinesArray[$i][181]','$allLinesArray[$i][182]','$allLinesArray[$i][183]','$allLinesArray[$i][184]','$allLinesArray[$i][185]','$allLinesArray[$i][186]','$allLinesArray[$i][187]','$allLinesArray[$i][188]','$allLinesArray[$i][189]','$allLinesArray[$i][190]','$allLinesArray[$i][191]','$allLinesArray[$i][192]','$allLinesArray[$i][193]','$allLinesArray[$i][194]','$allLinesArray[$i][195]','$allLinesArray[$i][196]','$allLinesArray[$i][197]','$allLinesArray[$i][198]','$allLinesArray[$i][199]','$allLinesArray[$i][200]','$allLinesArray[$i][201]','$allLinesArray[$i][202]','$allLinesArray[$i][203]','$allLinesArray[$i][204]')";
            
            
    //echo($allRecords);
        
    }
            
            
            
    $insert mysql_query("INSERT INTO placements(id, har_id, guar_num, last_name, first_name, middle_name, ss_num, dob,sex, marital_status, admin_date,admin_time, discharge_date, discharge_time, address_1, address_2, city, state, zip, ept_country, home_phone, work_phone, mobile_phone, employer, employer_address_1, employer_address_2, employer_city, employer_state, employer_zip, employer_country, employer_phone, acct_base_class, fin_class, total_charges, sbo_self_pay, sbo_bad_debt_bal, acct_bal, sbo_total_payments, sbo_total_adjustments, guarantor_last, guarantor_first, guarantor_ss_num, guarantor_dob, relationship, billing_address_1, billing_address_2, billing_city, billing_state,billing_zip, billing_country, billing_home_phone, billing_work_phone, ear_employer, ear_employer_address_1, ear_employer_address_2, ear_employer_city, ear_employer_stateear_employer_zip, ear_employer_country, ear_employer_phone, cvg_payor, claim_admission_type, claim_admission_source, claim_discharge_disposition,claim_occurence_code_1, har_occurence_code_1, claim_occurence_code_2, har_occurence_code_2, claim_occurence_code_3, har_occurence_code_3, claim_occurence_code_4, har_occurence_code_4, claim_condition_code_1, claim_condition_code_2, claim_value_code_1, har_value_code_amount_1, claim_value_code_2, har_value_code_amount_2, har_admission_diag, har_diag_code_1, har_diag_code_2, har_diag_code_3, har_diag_code_4, har_diag_code_5, har_diag_code_6, har_diag_code_7, har_diag_code_8, procedure_1, procedure_date_1, procedure_2, procedure_date_2, procedure_3, procedure_date_3, procedure_4, procedure_date_4, procedure_5, procedure_date_5, attending_physician_internal_num_1, attending_physician_internal_num_2, attending_physician_1, referring_provider_21, referring_provider_2, har_guar_id) VALUES" $allRecords);
        
            
    $result $insert;
            
    sendResults();    
    }


    function 
    sendResults(){
        global 
    $result;
        echo 
    "<br>RESULT: " $result;
        echo 
    "RESULT: $result";



    when I print out the $allRecords var.. I get data like this:

    ('',Array[1],'Array[2]','Array[3]','','','Array[4]','Array[5]','Array[6]','Array[7]','Array[8]','Array[9]','Array[10]','Array[11]','

    it seems to be putting the dataType or something?

    but this prints out fine:
    //echo("CHECK: " . $allLinesArray[$i][142] . "<br>");
    //echo("CHECK: " . $allLinesArray[$i][2] . "<br>");


    What am I doing wrong?

  2. #2
    Senior Member
    Join Date
    Aug 2006
    Posts
    322
    I noticed some of the things that should taken care of:

    1. If ID is AI, then you don't have to put any data in your $allRecords .= "('','$allLinesArray[$i][1]', the first empty string not needed.

    2. $insert = mysql_query("INSERT INTO placements(id, har_id,, you don't have to mention id as this is AI.

    3. Also, I found some empty string in the area of '$allLinesArray[$i][3]','','','$allLinesArray[$i][4]'. which you might have to match with your MySQL field and also you have to check both the $allRecords and the $insert = mysql_query("INSERT INTO placements to match every value and the array count should have to match with the count of insert fields.

    Hope you will find the cause of not inserting data into MySQL.



    marlopax

  3. #3
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,697
    thanks..

    actually breaking up the ' $allRecords var.. so I broke up the string, where the variable was... got me actual data output....

    I left values blank right there.. for a reason (for now)... I will eventually need to parse the name again.. as it a full name separated by commas.. (I am just dumping the full F, L, M name to one field for now.. but will break up the F, L, M names so they can to their own columns.. (and be searchable as well)

    still can NOT figure out why it wont INSERT into the database though??


    not even an error or anything?


    thanks


    current code:

    PHP Code:
    //** first index is ID# (auto-populated)        
            
    $allRecords .= "('','" $allLinesArray[$i][1] . "' ,'" $allLinesArray[$i][2] . "' ,'" $allLinesArray[$i][3] . "' ,'','','" $allLinesArray[$i][4] . "' ,'" $allLinesArray[$i][5] . "' ,'" $allLinesArray[$i][6] . "' ,'" $allLinesArray[$i][7] . "' ,'" $allLinesArray[$i][8] . "' ,'" $allLinesArray[$i][9] . "' ,'" $allLinesArray[$i][10] . "' ,'" $allLinesArray[$i][11] . "' ,'" $allLinesArray[$i][12] . "' ,'" $allLinesArray[$i][13] . "' ,'" $allLinesArray[$i][14] . "' ,'" $allLinesArray[$i][15] . "' ,'" $allLinesArray[$i][16] . "' ,'" $allLinesArray[$i][17] . "' ,'" $allLinesArray[$i][18] . "' ,'" $allLinesArray[$i][19] . "' ,'" $allLinesArray[$i][20] . "' ,'" $allLinesArray[$i][51] . "' ,'" $allLinesArray[$i][52] . "' ,'" $allLinesArray[$i][53] . "' ,'" $allLinesArray[$i][54] . "' ,'" $allLinesArray[$i][55] . "' ,'" $allLinesArray[$i][56] . "' ,'" $allLinesArray[$i][57] . "' ,'" $allLinesArray[$i][58] . "' ,'" $allLinesArray[$i][59] . "' ,'" $allLinesArray[$i][60] . "' ,'" $allLinesArray[$i][61] . "' ,'" $allLinesArray[$i][62] . "' ,'" $allLinesArray[$i][63] . "' ,'" $allLinesArray[$i][64] . "' ,'" $allLinesArray[$i][65] . "' ,'" $allLinesArray[$i][66] . "' ,'" $allLinesArray[$i][67] . "' ,'" $allLinesArray[$i][140] . "' ,'" $allLinesArray[$i][141] . "' ,'" $allLinesArray[$i][142] . "' ,'" $allLinesArray[$i][143] . "' ,'" $allLinesArray[$i][144] . "' ,'" $allLinesArray[$i][145] . "' ,'" $allLinesArray[$i][146] . "' ,'" $allLinesArray[$i][147] . "' ,'" $allLinesArray[$i][148] . "' ,'" $allLinesArray[$i][149] . "' ,'" $allLinesArray[$i][150] . "' ,'" $allLinesArray[$i][151] . "' ,'" $allLinesArray[$i][152] . "' ,'" $allLinesArray[$i][153] . "' ,'" $allLinesArray[$i][154] . "' ,'" $allLinesArray[$i][155] . "' ,'" $allLinesArray[$i][156] . "' ,'" $allLinesArray[$i][157] . "' ,'" $allLinesArray[$i][158] . "' ,'" $allLinesArray[$i][159] . "' ,'" $allLinesArray[$i][160] . "' ,'" $allLinesArray[$i][161] . "' ,'" $allLinesArray[$i][162] . "' ,'" $allLinesArray[$i][163] . "' ,'" $allLinesArray[$i][164] . "' ,'" $allLinesArray[$i][165] . "' ,'" $allLinesArray[$i][166] . "' ,'" $allLinesArray[$i][167] . "' ,'" $allLinesArray[$i][168] . "' ,'" $allLinesArray[$i][169] . "' ,'" $allLinesArray[$i][170] . "' ,'" $allLinesArray[$i][171] . "' ,'" $allLinesArray[$i][172] . "' ,'" $allLinesArray[$i][173] . "' ,'" $allLinesArray[$i][174] . "' ,'" $allLinesArray[$i][175] . "' ,'" $allLinesArray[$i][176] . "' ,'" $allLinesArray[$i][177] . "' ,'" $allLinesArray[$i][178] . "' ,'" $allLinesArray[$i][179] . "' ,'" $allLinesArray[$i][180] . "' ,'" $allLinesArray[$i][181] . "' ,'" $allLinesArray[$i][182] . "' ,'" $allLinesArray[$i][183] . "' ,'" $allLinesArray[$i][184] . "' ,'" $allLinesArray[$i][185] . "' ,'" $allLinesArray[$i][186] . "' ,'" $allLinesArray[$i][187] . "' ,'" $allLinesArray[$i][188] . "' ,'" $allLinesArray[$i][189] . "' ,'" $allLinesArray[$i][190] . "' ,'" $allLinesArray[$i][191] . "' ,'" $allLinesArray[$i][192] . "' ,'" $allLinesArray[$i][193] . "' ,'" $allLinesArray[$i][194] . "' ,'" $allLinesArray[$i][195] . "' ,'" $allLinesArray[$i][196] . "' ,'" $allLinesArray[$i][197] . "' ,'" $allLinesArray[$i][198] . "' ,'" $allLinesArray[$i][199] . "' ,'" $allLinesArray[$i][200] . "' ,'" $allLinesArray[$i][201] . "' ,'" $allLinesArray[$i][202] . "' ,'" $allLinesArray[$i][203] . "' ,'" $allLinesArray[$i][204] . "' ,'" $allLinesArray[$i][205] . "')";
            
            
    //echo($allRecords[1] . "<br>");
            //echo($allRecords[2] . "<br>");
            //echo($allRecords);
        
    }
        echo(
    $allRecords);
            
            
            
    $insert mysql_query("INSERT INTO placements(id, har_id, guar_num, last_name, first_name, middle_name, ss_num, dob,sex, marital_status, admin_date,admin_time, discharge_date, discharge_time, address_1, address_2, city, state, zip, ept_country, home_phone, work_phone, mobile_phone, employer, employer_address_1, employer_address_2, employer_city, employer_state, employer_zip, employer_country, employer_phone, acct_base_class, fin_class, total_charges, sbo_self_pay, sbo_bad_debt_bal, acct_bal, sbo_total_payments, sbo_total_adjustments, guarantor_last, guarantor_first, guarantor_ss_num, guarantor_dob, relationship, billing_address_1, billing_address_2, billing_city, billing_state,billing_zip, billing_country, billing_home_phone, billing_work_phone, ear_employer, ear_employer_address_1, ear_employer_address_2, ear_employer_city, ear_employer_stateear_employer_zip, ear_employer_country, ear_employer_phone, cvg_payor, claim_admission_type, claim_admission_source, claim_discharge_disposition,claim_occurence_code_1, har_occurence_code_1, claim_occurence_code_2, har_occurence_code_2, claim_occurence_code_3, har_occurence_code_3, claim_occurence_code_4, har_occurence_code_4, claim_condition_code_1, claim_condition_code_2, claim_value_code_1, har_value_code_amount_1, claim_value_code_2, har_value_code_amount_2, har_admission_diag, har_diag_code_1, har_diag_code_2, har_diag_code_3, har_diag_code_4, har_diag_code_5, har_diag_code_6, har_diag_code_7, har_diag_code_8, procedure_1, procedure_date_1, procedure_2, procedure_date_2, procedure_3, procedure_date_3, procedure_4, procedure_date_4, procedure_5, procedure_date_5, attending_physician_internal_num_1, attending_physician_internal_num_2, attending_physician_1, referring_provider_21, referring_provider_2, har_guar_id) VALUES" $allRecords);
        
            
    $result $insert;
            
    sendResults();    
    }


    function 
    sendResults(){
        global 
    $result;
        echo 
    "<br>RESULT: " $result "<br>";
        echo 
    "RESULT: $result";


  4. #4
    Senior Member
    Join Date
    Aug 2006
    Posts
    322
    I have done a small test of exactly same format that you posted, and all works for me.

    PHP Code:
    <?PHP
    function insert(){
    $connect=mysql_connect("localhost","root","")or die("mysql_error");
    $db=mysql_select_db("records")or die("db error");
    $allLinesArray=array(
    array(
    "","your first name"),
    array(
    "","your first name",""),
    array(
    "","","your first name","your last name"),
    array(
    "","","your first name","your last name","your mail id")
    );
    $allRecords ="";
    $allRecords .="('".$allLinesArray[0][1]."','".$allLinesArray[1][2]."','".$allLinesArray[2][3]."','".$allLinesArray[3][4]."')"

    echo 
    $allRecords;


    $query mysql_query("INSERT INTO placements(first_name,mid_name,last_name,email)VALUES".$allRecords);

    $result=$query;

    sendResults($result);    
    }
    function 
    sendResults($result){
        echo 
    "<br>RESULT: " $result "<br>";
        echo 
    "RESULT: $result";
    }  

    insert();
    ?>
    Here also the id field is primary and AI.

    marlopax

  5. #5
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,697
    it was due to a couple things in the end..

    mis-matched count in the records/values...

    and a typo in the database column name.. (had a space before it somehow?)

    anyways.. once the syntax was fixed and a little error checking thrown it.. it was solved.

    thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width


HTML5 Development Center