p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: problem coverting array to string to input into MySQL


Message #1 by "Bob Leitner" <bleitner@c...> on Tue, 11 Feb 2003 16:40:11
Hi all-

I believe this is a PHP issue, but it could be a MySQL one. Basically I 
have a form that dynamically generates a fieldset of check boxes The 
checkboxes are named with an array by the name of the fieldset (eg. 
$fieldset[]). After the form is submited I then have an array of all the 
checkboxes that were selected from the form. My intention is to implode 
the array into a string and then store the string into a field in a MySQL 
DB. I don't have any problem retrieving the array and converting to a 
string, already tested by echo'ing implode(", ", $fieldset) which returns 
only the selected checkbox values in a comma delimited string. My problem 
happens when I INPUT in to the DB, the database only shows "Array" when 
looking at with a MySQL client or after retrieving from database and echo 
back out to the browser. I thought maybe it was because I was delimiting 
with a comma so I tried "&" and using just a space - same result. Then I 
tried enclosing the entire string in quotes ('') before INPUT into MySQL -
 agian same result. Need to have just be a string stored in the database -
 any ideas on how to achieve this? FYI - the field type for the database 
is varchar. Anyone encounter this before and have suggestion?

Thanx-
Bob
Message #2 by "Gellings, C.O." <gellingsco@p...> on Wed, 12 Feb 2003 23:40:02 +0100
Bob,
I've had similar problems. What I did was getting an echo of the 
SQL-statement, and then find out what was/is wrong. For me to give an apt 
reply, it's to vague what you're writing ... If I look at what you write, 
you might be entering the array in your SQL instead of your imploded value. 
(Don't use the same variable to implode. It will stay an array - that's my 
experience)
Carl
>Hi all-
>
>I believe this is a PHP issue, but it could be a MySQL one. Basically I
>have a form that dynamically generates a fieldset of check boxes The
>checkboxes are named with an array by the name of the fieldset (eg.
>$fieldset[]). After the form is submited I then have an array of all the
>checkboxes that were selected from the form. My intention is to implode
>the array into a string and then store the string into a field in a MySQL
>DB. I don't have any problem retrieving the array and converting to a
>string, already tested by echo'ing implode(", ", $fieldset) which returns
>only the selected checkbox values in a comma delimited string. My problem
>happens when I INPUT in to the DB, the database only shows "Array" when
>looking at with a MySQL client or after retrieving from database and echo
>back out to the browser. I thought maybe it was because I was delimiting
>with a comma so I tried "&" and using just a space - same result. Then I
>tried enclosing the entire string in quotes ('') before INPUT into MySQL -
>  agian same result. Need to have just be a string stored in the database -
>  any ideas on how to achieve this? FYI - the field type for the database
>is varchar. Anyone encounter this before and have suggestion?
>
>Thanx-
>Bob


  Return to Index