Jump to content

Need help with Array


alan.wittes

Recommended Posts

I am using PHP to take data from an HTML input form to a MYSQL database. I have an issue with one of my fields. The field is 'Language'. 

 

Here is what I am after: I need to have multiple 'Language' checkboxes, so that the user can check all the Languages they speak (could often be more than 1). For example, let's say the user selects 'Spanish' and 'Italian'. I would then like to store this value in my MYSQL database as 'Spanish, Italian'.

 

Below is my code as it stands today:

 

HTML Code:

<input name="AG_LANGUAGE[]" type="checkbox" value="Spanish" /> Spanish

<input name="AG_LANGUAGE[]" type="checkbox" value="Italian" /> Italian

 

PHP Code:

<?php

$language = (!empty($_POST['AG_LANGUAGE'])? implode(',',$_POST['AG_LANGUAGE'])."\n" : ''); 

?>

 

The problem I'm having is that the input data is being stored in my Language table field as 'Array'. Is there a way to store the actual values in the field instead (ex. 'Spanish, Italian')? If not, how do I extract the actual values using SQL? Writing a simple SQL query produces the below result:

 

select ag_language

  from ag_profile

 

'Array'

 

Thanks in advance for any help.

Link to comment
https://forums.phpfreaks.com/topic/58094-need-help-with-array/
Share on other sites

try printing AG_LANGUAGE before imploding it and see what you get.

Also echo $language and see what it is. if it says array, print the array and let me know what it is:

 

<?php
print_r($_POST['AG_LANGUAGE']);
$language = (!empty($_POST['AG_LANGUAGE'])? implode(',',$_POST['AG_LANGUAGE'])."\n" : ''); 
echo '<br />' . $language;
?>

Link to comment
https://forums.phpfreaks.com/topic/58094-need-help-with-array/#findComment-288047
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.