Almost got it,
but when trying to post data from a form with mutli-picklists (pull downs)
It posts the the first pick, but adds the word array to it, as an example I have a pull down that has 15 items on it, you can select multi-item, but only the first choice is posted to the database and the word array is added, so it looks like:

arrayArguing with Admin

Also, the other pick lists, also add the word array to the choices.

Snipet of the Form


<form enctype='multipart/form-data' action='process_1.php' method='post'>

<select name="Offense[]" class="textfield" multiple size="5">
<option value='Arguing with Admin'>Arguing with Admin (AA)</option>
<option value='Bug Exploit'>Bug Exploit (BE)</option>


<select name="Admin[]" class="textfield" multiple>
<option value='Acedel'>Acedeal</option>
<option value='Coby_Wan_Kenobi'>Coby_Wan_Kenobi</option>
<option value='Bush_8'>Bush_8</option>
<option value='Mschadt'>MsChadt</option>

<input type=submit value='Send' >

Forms Proccessor


<?php

include("admin/config.inc.php");

$errors=0;
$error="The following errors occured while processing your form input.<ul>";
$_POST['Notes']=preg_replace("/(\015\012)|(\015)|(\012)/","&nbsp;<br />",
$_POST['Notes']);if($_POST['Username']==""
|| $_POST['Offense']=="" || $_POST['Admin']=="" ||
$_POST['Date']=="" || $_POST['Time']=="" || $_POST['Server']=="" ||
$_POST['Notes']=="" ){

$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if($errors==1) echo $error;
else
{

$Offense = $_POST["Offense"];
if (is_array($Offense)) 
       {
  for ($i=0; $i<count($Offense); $i++)
 {
    $Offense .= $Offense[$i].", ";
  }
  $Offense = substr ($Offense, 0, strlen ($Offense)-2);
     } 
else 
    {
  $Offense = "";
     }

$Admin = $_POST["Admin"];
if (is_array($Admin)) {
  for ($i=0; $i<count($Admin); $i++)
     {
    $Admin .= $Admin[$i].", ";
  }
  $Admin = substr ($Admin, 0, strlen ($Admin)-2);
  } 
else  
{ $Admin = ""; } $Server = $_POST["Server"]; if (is_array($Server)) { for ($i=0; $i<count($Server); $i++) { $Server .= $Server[$i].", "; } $Server = substr ($Server, 0, strlen ($Server)-2); } else { $Server = ""; } $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$_SERVER['HTTP_HOST'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/")); $message="Username: ".$_POST['Username']." Offense: $Offense Admin: $Admin Date: ".$_POST['Date']." Time: ".$_POST['Time']." Server: $Server Notes: ".$_POST['Notes']." "; $link = mysql_connect($hostname,$username, $password) or die("Connetion to database failed!"); mysql_select_db($dbname); $query="insert into server_user_banlist (usernname,offense,admin,date,time,server,notes) values ('".$_POST['Username']."','$Offense','$Admin','".$_POST['Date']."','".$_POST['Time']."', '$Server','".$_POST['Notes']."')"; mysql_query($query); header("Refresh: 0;url=form8.html"); } ?>

I think I just about got it, but not sure if this is the correct way to do it, using an example, was not sure of if I needed to change all the words Offense to something different.

In this, should it refference Offense as the array and strings? (if that is the correct nomenclature)

$Offense = $_POST["Offense"];
if (is_array($Offense)) 
       {
  for ($i=0; $i<count($Offense); $i++)
 {
    $Offense .= $Offense[$i].", ";
  }
  $Offense = substr ($Offense, 0, strlen ($Offense)-2);
     } 
else 
    {
  $Offense = "";
     }

So it take Offense, and puts in the Actual Offense, is this the correct way to lay this out? And this little part will handel say 8 choices?

Somewhere doing something wrong, just do not know enough to figure it out yet..

Many Thanks again for putting up with one that is way lost 🙂
Regards
TB.

    2 options:

    while ($array_cell = each($array))	{		
    // Start loop to process each address in our array
    	$var_val = $array_cell['value'];		
    	$var_key = $array_cell['key'];
    // Define each of the 2 parts of our array line to the 2 parameters
    	$new_var .= $var_val . ", ";
    }

    OR

    foreach($var_arr as $var) {
    	$new_var .= $var . ", ";
    }

      Thanks for the reply,
      but get an error when trying those 2 suggestions

      When using the top suggestion I get this error

      while ($array_cell = each($array)) { //snip

      Warning: Variable passed to each() is not an array or object in

      Using option 2 I get this:

      foreach($var_arr as $var) {//snip

      Warning: Invalid argument supplied for foreach() in.

      Part of the problem is not real sure where to paste in your code suggestions. and or if I should remove parts of my code..

      Thanks for Helping
      And regards
      TB..

        Firstly, you can't just paste the snippets and expect them to work. They were generic examples.

        Rather than write your code for you, I'll try to explain what each is doing and hopefully you'll be able to figure out how to adapt it to what you are trying to achive.

        Both snippets will perform the same actions. They take an array in at the beginning and incrementally add the array values to one another to create a string.

        In the first example, I used "while":
        while ($array_cell = each($array)) {
        So this says that while you reach the end of the array (where $array would be the name of your array that you are trying to manipulate), create a single row array called $array_cell.
        This array_row has 2 elements, a key (its position in the original array) and a value (the bit that you want)
        So:
        $var_val = $array_cell['value'];

        $var_key = $array_cell['key'];
        is simply assigning those array elements to variables. Because we assign $array_cell['key'] to the variable $var_key, we can subsequently now use this variable as we wish.
        Finally we concatenate the variable $new_var with the value of $var_key and a character string ", " and then finally close the loop.

        In the second example, I've used the foreach construct. This in essense cycles through the array values one by one so that we can use those values.
        So:
        foreach($var_arr as $var) {
        tells php to assign the value of the array at each position to the new variable $var.
        $new_var .= $var . ", "; then cancatenates the variable $var to the end of the variable $new_var
        Then simply close the foreach.

        To use either of these methods, you need to replace the code in your script which condenses your arrays into string variables using suitable names etc.

        My apologies anyway as my original example had an error in the foreach example. It was 2am and I was well and truly ready for sleep ;-)

          🙂 🙂
          hahha, ok as the forum indicates, we be noobs here 🙂
          Trying to follow you (it's a big day if I just get the brackets and braces in the right spot)

            We were all n00bs once!

            But experience tells me that it isn't actually quite as helpful in the long run if somebody simply writes your code for you ready for you to cut and paste. By doing it with generic examples you would hopefully gain an understanding of the actual process involved and then by modifying the example to suit your own requirements, the principle would stick in your mind.

            Its the difference between learning parrot fashion and learning by example. You'll be far more prepared next time you come across a similar problem because you'll have worked through this one rather than simply being fed an answer. 🆒

              So if I follow this correctly;

              naming the selects with "Offense[]" designates an array named Offense. So...

              $Offense = $_POST["Offense"];

              would
              $_POST['Offense'] would just return the word array. , or take the first pick and then add the word array to it. Is this correct assumption??

              So this may work (Maybe)..

              foreach($Offense as $_POST["Rules"])
              {
              // loop here
              $Offense .= $Rules . ", ";
              echo $Rule.'<br />';
              }

              SO this should run through the array $Offense correct.?? Have not tested yet.

              foreach($Offense as $Rules) { 
              //tells php to assign the value of the array at each position to the //new variable $Rules . 
              $Rules .= $Offense . ", ";   //then cancatenates the variable $var to the end of the variable $new_var 
              Then simply close the foreach. 
              }
              

              I think I probally just got an "F" on siwis's test 🙂

                Unfortunately I don't think what you've written will work 😉

                foreach($Offense as $Rules) { 
                //tells php to assign the value of the array at each position to the //new variable $Rules . 
                $Rules .= $Offense . ", ";   //then cancatenates the variable $var to the end of the variable $new_var 
                Then simply close the foreach. 
                }

                What you have will repeatedly overwrite the variable $Rules for each iteration of the loop...
                If you want to end up with a comma seperated list of values then it should really be something like this:

                $new_var = implode(",", $Offence);
                

                Unless I've got it wrong in which case my defence is that it's been a long day 🙂

                  Originally posted by notionlogic
                  Unfortunately I don't think what you've written will work 😉

                  foreach($Offense as $Rules) { 
                  //tells php to assign the value of the array at each position to the //new variable $Rules . 
                  $Rules .= $Offense . ", ";   //then cancatenates the variable $var to the end of the variable $new_var 
                  Then simply close the foreach. 
                  }

                  What you have will repeatedly overwrite the variable $Rules for each iteration of the loop...
                  If you want to end up with a comma seperated list of values then it should really be something like this:

                  $new_var = implode(",", $Offence);
                  

                  Unless I've got it wrong in which case my defence is that it's been a long day 🙂 [/B]

                  Thanks for the reply!!
                  With me just learning the array bit, was not even sure what implode did, so with some great help to point out you can not invert the array values etc...came up with this..

                  // Offense Selection
                  $Offense = '';
                  foreach($_POST['Offense'] as $Rules)
                  	{
                  $Offense .= $Rules.', ';
                  	}
                  $textual_offense = substr($offense_string,0,-2);
                  

                  How does implode work different, or is it just better to use implode / explode ???

                  Now if I can just get the date to post in correct. I should be set with this one .. (for the time being anyway)

                    Write a Reply...