简体   繁体   中英

Codeigniter Issues with inserting arrays

This could ultimately prove not to be the issue, but I'll give a bit of background on the situation.

I've (attempted) to create a return goods authorization system for the business I work for. All internal testing seemed to indicated that the system was working as intended and that all bugs were fixed. My error log was empty and my javascript console showed nothing out of the ordinary.

On Certain Cases which I'm imagining is due to an outdated browser ( though I'm skeptical, because it seems to be a server side issue ) the 'returned' products are not being inserted into my database.

On submit, I'm gathering and putting in the user's contact information into a table in my database -- This works great and without issue.

Once I've gotten that information in, I'm then running a foreach loop on fields that have arrays for names.

foreach( $this -> input -> post('po_number') as $number => $value ){

    $ponum   = $this -> input -> post('po_number');
    $innum   = $this -> input -> post('inv_number');
    $qty     = $this -> input -> post('quantity');
    $panum   = $this -> input -> post('part_number');
    $desc    = $this -> input -> post('description');
    $reason = $this -> input -> post('reason');

    $insert_requests = array(
        'rga_id'        => $rga_no,
        'po_number'     => $ponum[$number],
        'inv_number'    => $innum[$number],
        'quantity'      => $qty[$number],
        'part_number'   => $panum[$number],
        'description'   => $desc[$number],
        'reason'        => $reason[$number]
    );

    if( $insert_requests['po_number'] != 0){

        $input = $this->db->insert('new_rga_returns', $insert_requests);
    }
}

So this is doing what I mentioned above. Each one of those "$this->input->post" 's is a field I have, which can be added via javascript / jQuery. Initially there's one row of inputs with the ability to add more as you see fit.

However, not even one row per "RGA" has been being sent through.

The most frustrating part is that ( as mentioned above ) whenever someone in the office inputs a request, it works (running win7 chrome V41). I've also tested on IE10 and the latest version of FireFox and everything runs fine. (Can't download older browsers due to compatibility)

We've had one person make a 'return' on their mac and that seemed to break it as well.

As far as I can tell, it seems to be an issue with different machines / browsers / operating systems handling the input arrays differently...

I ended up removing the

$insert_requests['po_number'] != 0

from my if statement and simply replaced it with

if( $insert_requests ) { ... }

Stupid thing to put in there in the first place on my behalf. Thanks to those who commented.

EDIT FOR CLARIFICATION

Should have been checking if the insert request even existed instead of seeing if it was equal to something or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM