Connecting Tech Pros Worldwide Help | Site Map

how to seperate values and place in array

anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#1: Oct 8 '09
hi,

this is quite a simple question....I have generated 2000 passwords for an ebook, and i want to place them all into a database so that when a person purchases the ebook they are then lead to a page where they have to confirm their email address and will then be shown a password for the ebook. the passwords are called at random from a db.

instead of putting them in one by one i want to just copy and paste them (seperated by commas) into one textarea that once i submit the form php will seperate them by the commas and place them in an array to put into the database

what is the best method to do this? can someone point me in the right direction
Atli's Avatar
Moderator
 
Join Date: Nov 2006
Location: Iceland
Posts: 3,736
#2: Oct 8 '09

re: how to seperate values and place in array


Hey.

Why do you generate the passwords ahead of time? Why not just create a random password when the user purchases the ebook and add it to the database then?

Or, better yet, have the user choose his own password.

Anyways, if you have a comma-separated list of strings, you can use explode to split them into an array, and then implode to re-assemble them.

A MySQL query to insert multiple values into a field should be:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO `table`(`field`) VALUES('val1'), ('val2'), ('valN');
anfetienne's Avatar
Needs Regular Fix
 
Join Date: Feb 2009
Location: UK
Posts: 356
#3: Oct 8 '09

re: how to seperate values and place in array


im generating the passwords before hand because the passwords have to be including when the ebook is compiled.....this is just a means to get the password to the person that buys the ebook.

unfortunately there is no other way to do it with the security features of ebook compilers.
Dormilich's Avatar
Moderator
 
Join Date: Aug 2008
Location: Leipzig, Germany
Posts: 3,629
#4: Oct 8 '09

re: how to seperate values and place in array


Quote:

Originally Posted by anfetienne View Post

instead of putting them in one by one i want to just copy and paste them (seperated by commas) into one textarea that once i submit the form php will seperate them by the commas and place them in an array to put into the database

if you connect to your DB with a MySQL client, you can can bypass forms and PHP, for most clients support direct SQL execution.
Reply