Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2007
    Posts
    154
    Thanks
    52
    Thanked 0 Times in 0 Posts

    Posting Values from Array

    Hi guys. I have a form which returns an array:

    [furn_flag] => Array
    (
    [0] => something
    [1] =>
    [2] => something else
    )


    (note [1] is blank)

    How do I insert the values into my database (foreach?) as individual rows?

    For example in the above case inserted into a table called Flags would be:

    array_id = 0, array_text=something
    array_id = 2, array_text=something else

    The blank array would not be inserted...

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The blank array would not be inserted...
    Make use of array_filter() to remove the empty cells.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Jan 2007
    Posts
    154
    Thanks
    52
    Thanked 0 Times in 0 Posts
    Thanks. I've inserted that into my code which now looks like this:

    PHP Code:
    $furn_array = (array_filter($_POST['furn_flag']));

    foreach (
    $furn_array as $id=>$title)


    {
        
    $quote_id $_POST['quote_id'];
    $name $quote_id '-' $id;
    $date gmdate('Y-m-d H:i:s');

    $result mysql_query("UPDATE dbFlags SET edited='$date',title='$title',name='$name'");
        
    if (
    mysql_affected_rows()==0) {

    $result mysql_query("INSERT INTO dbFlags (edited,title,name) VALUES ('$edited','$title','$name')");
        
    }

    An example of the returned array would be:
    Array ( [1] => First Thing [2] => Second Thing )

    The mysql update (or insert) works only for the last array however. What am I missing?


  •  

    Tags for this Thread

    Posting Permissions

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