kemu_ wrote:If you just try to save the array you got from the html-form into database, it will just save Array there. Array-type variables cant be saved in "array-form" into database. But you can save it by using serialize function
$stuff_to_insert_into_db = serialize($array_you_got_from_html);
When you get the the data back from database, you need to unserialize it, so you can use it as an array again.
$array = unserialize($data_from_db);
Thanks for immediate response. I have a function to retrive data from database and populate into a multiselect list box. I need to insert the selected data to another table. for example, if the user_id (it comes after login) is 675, the result in my table should be:
user_id | soft_id
675 1
675 3
675 15
. .
. .
. .
The sunction and Insert code are as follows:
function get_software_list($soft_id= "")
{
$sql = "SELECT * FROM software ORDER BY software ASC;";
$query = mysql_query($sql);
if($row = mysql_fetch_array($query))
{
$str .= "<select name='soft_id[]' size=\"10\" multiple >\n";
//$str .= "<option value=\"\">Please choose . . .</option>\n";
do
{
if($soft_id == $row["soft_id"])
{
$str .= "<option value=\"" . $row["soft_id"] . "\" selected=\"selected\">" . $row["software"] . "</option>\n";
}
else
{
$str .= "<option value=\"" . $row["soft_id"] . "\">" . $row["software"] . "</option>\n";
}
}
while($row = mysql_fetch_array($query));
$str .= "</select>\n";
}
return $str;
}
The Insert code:
// insert into "res_user_software"
foreach($_POST as $key => $value)
{
if(strstr($key, "soft_id") && !is_blank($value))
{
$sql = "INSERT INTO res_user_software (user_id, soft_id) VALUES ('" . $user_id . "', '" . $value . "');";
mysql_query($sql);
}
}
I would be thankful to have your help.
Thanks again
Mojgan