explode() problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    explode() problems

    hi everyone

    i am getting a bunch of values from a form via post all of the information that this question deals with is from series of check boxes below is the code that creates the check boxes
    the logic behind it is it gets a bunch of listing from the database and if $group is not null then the first check box is checked and a second created else only one unchecked checkbox is created
    [PHP]
    $result=mysql_q uery("SELECT TITLE, FNMI, LN, COMPANY, E_MAIL, id, $group FROM DBASE ORDER BY LN");
    while($row = mysql_fetch_row ($result))
    {
    if ($row[4] != NULL)
    {
    if($row[6] != NULL)
    {
    echo "<input type='checkbox' name='$row[5]' value='$row[5]' checked='checke d'>";
    echo $row[2], ", ", $row[1], "<input type='checkbox' name='del", $row[5], "' value='$row[5]'><br>\n";
    }else{
    echo "<input type='checkbox' name='$row[5]' value='$row[5]'>";
    echo $row[2], ", ", $row[1], "<br>\n";
    }
    }
    }
    [/PHP]

    this then goes to the processing script
    here i send the $_POST array through a foreach loop getting both the key and the value stored into variables
    then i make sure the value is_numeric
    then i explode the key to get the 'del' off and store it into the delete array
    next i have a sql select statement followed by a loop that walks through all rows of the select
    when i am in this loop my $delete array is non existent i've printed it out right below where i make it and it is fine i've even assigned $delete[1] which holds the value i need to a variable and printed that out and it works before the loop but in the loop those variables don't seem to exits
    below is that code
    [PHP]
    foreach($_POST as $key => $value)
    {
    if(is_numeric($ value))
    {
    $delete = explode("del", $key);
    $del = $delete[1];
    echo $del;//it is displayed here
    $result = mysql_query("SE LECT id, $new FROM DBASE WHERE id = $key OR $new IS NOT NULL");

    while ($row = mysql_fetch_row ($result))
    {

    if ($row[0] == $key)
    {
    if ($row[1] == NULL)
    {
    mysql_query("UP DATE `DBASE` SET `$new` = 'X' WHERE `id` = $key LIMIT 1");
    }
    }
    echo $del; //but not here
    if ($row[0] == $del)
    {
    mysql_query("UP DATE `DBASE` SET `$new` = NULL WHERE `id` = $row[0] LIMIT 1");
    }

    }
    }
    }
    [/PHP]
    for the values where there were two check boxes the values are the same one of the keys has a 'del' in front of it the problem i seem to be having is when i explode the 'del' off the key
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    I am not in a sure for these type of line just check the HTML source for this.
    [PHP]echo "<input type='checkbox' name='$row[5]' value='$row[5]'>";[/PHP]

    it should display like
    name= ' valuegoeshere '

    Note that single quotes. then how to fetch this form element from next php page.

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      It may actually be the case that you are not ever getting inside that while loop, and therefore you are never hit the second echo.

      Originally posted by tolkienarda
      hi everyone

      i am getting a bunch of values from a form via post all of the information that this question deals with is from series of check boxes below is the code that creates the check boxes
      the logic behind it is it gets a bunch of listing from the database and if $group is not null then the first check box is checked and a second created else only one unchecked checkbox is created
      [PHP]
      $result=mysql_q uery("SELECT TITLE, FNMI, LN, COMPANY, E_MAIL, id, $group FROM DBASE ORDER BY LN");
      while($row = mysql_fetch_row ($result))
      {
      if ($row[4] != NULL)
      {
      if($row[6] != NULL)
      {
      echo "<input type='checkbox' name='$row[5]' value='$row[5]' checked='checke d'>";
      echo $row[2], ", ", $row[1], "<input type='checkbox' name='del", $row[5], "' value='$row[5]'><br>\n";
      }else{
      echo "<input type='checkbox' name='$row[5]' value='$row[5]'>";
      echo $row[2], ", ", $row[1], "<br>\n";
      }
      }
      }
      [/PHP]

      this then goes to the processing script
      here i send the $_POST array through a foreach loop getting both the key and the value stored into variables
      then i make sure the value is_numeric
      then i explode the key to get the 'del' off and store it into the delete array
      next i have a sql select statement followed by a loop that walks through all rows of the select
      when i am in this loop my $delete array is non existent i've printed it out right below where i make it and it is fine i've even assigned $delete[1] which holds the value i need to a variable and printed that out and it works before the loop but in the loop those variables don't seem to exits
      below is that code
      [PHP]
      foreach($_POST as $key => $value)
      {
      if(is_numeric($ value))
      {
      $delete = explode("del", $key);
      $del = $delete[1];
      echo $del;//it is displayed here
      $result = mysql_query("SE LECT id, $new FROM DBASE WHERE id = $key OR $new IS NOT NULL");

      while ($row = mysql_fetch_row ($result))
      {

      if ($row[0] == $key)
      {
      if ($row[1] == NULL)
      {
      mysql_query("UP DATE `DBASE` SET `$new` = 'X' WHERE `id` = $key LIMIT 1");
      }
      }
      echo $del; //but not here
      if ($row[0] == $del)
      {
      mysql_query("UP DATE `DBASE` SET `$new` = NULL WHERE `id` = $row[0] LIMIT 1");
      }

      }
      }
      }
      [/PHP]
      for the values where there were two check boxes the values are the same one of the keys has a 'del' in front of it the problem i seem to be having is when i explode the 'del' off the key

      Comment

      Working...