Help With Array!!!

Discussion in 'PHP' started by ladieballer2004, Aug 17, 2009.

  1. #1
    Ok so here it goes: I have an array that is attached to a web form. It's function is to ask the user what she has been involved in. There are 3 rows with 4 columns each. The user is required to fill out at least one row but not all three.
    Here is the problem. When I test it out all three rows are entered into the database wether they hold information or not. How do I get the parser to recognize when a row is blank and ignore it before the info is inserted into the database?

    Here is the PHP Code for the Array
    foreach($_POST['Activity'] as $row=>$Act)
    {
    $Activity=($Act);
    $Position=($_POST['Position'][$row]);
    $StartDate=($_POST['StartDate'][$row]);
    $EndDate=($_POST['EndDate'][$row]);

    if (!empty($Act)) {
    $involv = "INSERT INTO Involvement (Activity, Position, StartDate, EndDate)
    VALUES ('$Activity','$Position','$StartDate','$EndDate')";
    };

    Thanks in advance
     
    ladieballer2004, Aug 17, 2009 IP
  2. ct2k7

    ct2k7 Peon

    Messages:
    457
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could use regex, which I've never used before, and I'd certainly be interested in the solution you will embark on, because I need to implement a similar system in my intranet project.
     
    ct2k7, Aug 17, 2009 IP
  3. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    if (!empty($Act) && !empty($Position) && !empty($StartDate) && !empty($EndDate)) {
    
    }
    
    PHP:
    ?
     
    premiumscripts, Aug 17, 2009 IP
  4. ct2k7

    ct2k7 Peon

    Messages:
    457
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks, I've never heard of empty :(
     
    ct2k7, Aug 17, 2009 IP
  5. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The other is isset()
     
    kblessinggr, Aug 17, 2009 IP
  6. ct2k7

    ct2k7 Peon

    Messages:
    457
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I use that :D
     
    ct2k7, Aug 17, 2009 IP