Page 1 of 1

3 days - so I'll ask - arrays

Posted: Fri Mar 14, 2008 12:06 am
by ppgpilot
hi

I have a multi checkbox entry that I want to place into a mysql database.

I then need to pull the array data out of the db and display into a <select> box.

I know this is easy, but have not found the way to accomplish the task.

I have tried numerous ideas I found from the web, but nothing works - most of the time I get "Array" displayed

I have tried searilize() but just get s:5:"Array" in the mysql db table column

I can create an array and work with it, no problem - but I can't get the checkbox name="[]" value"xxx" to work in any fashion - I only get "Array" to display.

so here is the code:

Code: Select all

<input type="checkbox" name="features[]"  value="blue"  />
<input type="checkbox" name="features[]"  value="red"  />
<input type="checkbox" name="features[]"  value="yellow"  />
<input type="checkbox" name="features[]"  value="orange"  />
process:

Code: Select all

if(isset($_POST['features']))
{
$features = $_POST['features'];
}
 
print_r($features);  // =   Array ( [0] => Array ) 
echo "<br /><br />";
var_dump($features); //   =    array(1) { [0]=> string(5) "Array" }
This will not enter the database nor can I work with it in a loop: foreach, while, or for

So what am I doing wrong?

Any help would be appreciated...

David

Re: 3 days - so I'll ask - arrays

Posted: Fri Mar 14, 2008 12:23 am
by Frank Shi
hi

I have a multi checkbox entry that I want to place into a mysql database.

I then need to pull the array data out of the db and display into a <select> box.

I know this is easy, but have not found the way to accomplish the task.

I have tried numerous ideas I found from the web, but nothing works - most of the time I get "Array" displayed

I have tried searilize() but just get s:5:"Array" in the mysql db table column

I can create an array and work with it, no problem - but I can't get the checkbox name="[]" value"xxx" to work in any fashion - I only get "Array" to display.

so here is the code:

Code: Select all

<input type="checkbox" name="features[]"  value="blue"  />
<input type="checkbox" name="features[]"  value="red"  />
<input type="checkbox" name="features[]"  value="yellow"  />
<input type="checkbox" name="features[]"  value="orange"  />
process:

Code: Select all

if(isset($_POST['features']))
{
$features = $_POST['features'];
}
 
print_r($features);  // =   Array ( [0] => Array ) 
echo "<br /><br />";
var_dump($features); //   =    array(1) { [0]=> string(5) "Array" }
This will not enter the database nor can I work with it in a loop: foreach, while, or for

So what am I doing wrong?

Any help would be appreciated...

David[/quote]

Code: Select all

 

need all code

Re: 3 days - so I'll ask - arrays

Posted: Fri Mar 14, 2008 12:25 am
by Christopher
Do you have a form? Try this code:

Code: Select all

<form action="" method="post">
blue<input type="checkbox" name="features[]"  value="blue"  />
red<input type="checkbox" name="features[]"  value="red"  />
yellow<input type="checkbox" name="features[]"  value="yellow"  />
orange<input type="checkbox" name="features[]"  value="orange"  />
<input type="submit" name="submitform"  value="submit"  />
</form>
<?php
if(isset($_POST['features']))
{
    $features = $_POST['features'];
 
    print_r($features);  // =   Array ( [0] => Array )
    echo "<br /><br />";
    var_dump($features); //   =    array(1) { [0]=> string(5) "Array" } 
}