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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.