That's because it is an array. You'll need to extract the values from it before adding them to the database.

And take out all those stupid and unneccessary <font> and <span> tags. You must have used some crap code generater like FontPage to end up with all of them in there.

    I am sorry, I don't know what you mean by "extract the values from it"?

      Same way you extract the values from the POST array, by index or key. Look up arrays in the manual and the functions for manipulating them.

        Are you referring to this?

        <?php
        $arr = array("activities" => array(1 => Camping, 2 => RVing, 3 => Hiking, 4 => Boating, 5 => Fishing, 6 => Hunting, 7 => WildlifeWatching, 8 => PicnicAreasPlayground, 9 => Geocaching));
        ?>

        Is so where do I insert this? With the form or in the php code that inserts to the DB?

        -Thanks

          OK :rolleyes:

          You have a group of checkboxes named 'activities[]' (and there should not be a gap between [ and ] ).
          If the user clicks at least 1 checkbox then the form will post the array called 'activities'. This will contain the values for all of the checkboxes clicked.
          How you access the contents depends on what you want to do with the data.

          // check to see if any activities were clicked
          if (isset($_POST['activities'])) {
          
          // check to see if it really is an array
          if (is_array($_POST['activities'])) {
          
          // want a comma seperated list then use implode()
          $str_activities = implode(',' , $_POST['activities']);
          
          // want to process each element one at a time
          foreach($_POST['activities'] as $val) {
             echo $val;
          }
          
          // want to test if a specific box was clicked
          if (in_array('camping', $_POST['activities'])) {
          
          

            ok Thanks I understand that, but where does this need to be placed. I have two files, one that contains the HTML with the form. and another that the form calls and inserts all the info into the DB. So while all of this is making sense I do not know where to put the suggested code and I have not found a tut that explains otherwise.

            The form can been seen in the link of my first post. Just so were on the same page. I want the value of each checkbox entered into the DB should it be click. I.E. Camping and fishing is checked I want it to be displayed as Camping, Fishing. in the DB and so on.

            -Thanks

              In the form that is being called...ie. <<< I have two files, one that contains the HTML with the form. and "another that the form calls " and inserts all the info into the DB. So while all of this is making >>>>

              $str_activities = $_POST['activities'];

              $str_activities = preg_replace("#<.+?>(.+?)</.+?>#is", "\1", $str_activities);

              the above code is the one that u need to change to an loop to look for the values in array of activities.

              comming to the database part of it, in the database have u got one field set for the activites or more than one. because u need more than one field in the database for the activities because it gonna be more than one activities that get selected. If u want only one field to get into the database might be u need to combine all activities into one string and then insert it into the database.

              "I might be wrong because i dont know how u r database is going to be and what u r gonna use the activities for".

              hope that gives u an idea of what changes need to be done.

                Ah, so you're another regular expression aficionado msk. 🆒

                Don't understand why you think one is needed here though. 😕 The data in the array is the data we define in the html form code. If it's not what we need then redefine it there.

                Dada, if you want to store the activities as a comma-seperated list in 1 column then just implode() the array into a string, see my example above.

                  sorry roger i think u got me wrong. I am just explaining him the both options he has got but didnt prefer one over the other.
                  As i told "I might be wrong because i dont know how u r database is going to be and what u r gonna use the activities for".
                  sorry if i passed the wrong impression.

                    Still don't see where preg-replace fits into this, whatever way you wanted to use or store the data. It's an array - and an array containing pre-defined values at that. !!!???

                      No I understand how the array works now. I still don't know where extactly the code is suppose to be placed. I have just started learning PHP just a couple of weeks ago, but I am trying to learn and understand. So some of the things you explain are still greek to me. Yes I want whatever is selected to be entered into one column which I am able to do now.

                      This is what I have done so far, I have replaced this line

                      $str_activities = $_POST['activities'];  

                      With this one.

                      $str_activities = implode(',' , $_POST['activities']);

                      Now everything is being entered, but only 3 values are going into the DB. It's like thier is a limit on how many can be entered. To test this I actually went and entered all of them in groups of three and they all go in, but It won't enter more then 3 into the DB if more then 3 are checked. Is thier a limit on how many you can have?

                      -Thanks Again.

                        Yes, it's the limit imposed by the size of the column that you have defined. So what data type have you set for the column? And what is the maximum storage capacity of that data type? Don't ask us about it, go and read the manual.

                          Thank you, I have got it now. You could be a little more for forgiving to those just starting and leaning PHP though. Can't very well read the manual on something If I don't know exactly what I am looking for. That's like going on a road trip and not knowing where you're going. I mean you know how to drive, but that doesn't mean know how to go where you have never been before, right? You could have just said "Check the size of your column" I mean you are on a newbie support forum after all. Just remember you will need help on something some day and your actions of how you treat others could effect how your problem gets resolved. besides that everyone has to start somewhere right?

                          -Thanks for you help, I really do appericate it.

                            Write a Reply...