multiple select box - result saved as 1 string

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 979
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Thu Jun 16, 2011 3:53 am

change this:

Code: Select all

<?php
   $test=$_POST['test'];
   if ($test){
    foreach ($test as $t){echo 'You selected ',$t,'<br />';}
   }
?>
to this:

Code: Select all

<?php
   $test=(isset($_POST['test'])) ? $_POST['test'] : array();
//if something wasn't selected it still initializes an empty array

   $output = explode(" ",$test); //separate all elements into a space delimited string
?>

Now you just need to write the query that will insert that value to a database table.

User avatar
Nullsig
php-forum Fan User
php-forum Fan User
Posts: 979
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Fri Jun 17, 2011 4:24 am

So funny story, I always mix up which function does which....

The correct code is actually:

Code: Select all

<?php
   $test=(isset($_POST['test'])) ? $_POST['test'] : array();
//if something wasn't selected it still initializes an empty array

   $output = implode(" ",$test); //separate all elements into a space delimited string
?>

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests