I'm having some issues inserting an array into a mysql database.
Here's the background info:
This is the table structure in the database:
CREATE TABLE `getListed` (
timeStamp timestamp(14) NOT NULL,
firstname varchar(25) binary NOT NULL default '',
lastname varchar(25) binary NOT NULL default '',
bizname varchar(25) binary NOT NULL default '',
street varchar(40) binary NULL default '',
city varchar(25) binary NULL default '',
county varchar(25) binary NOT NULL default '',
postcode varchar(15) binary NULL default '',
phone varchar(25) binary NOT NULL default '',
email varchar(35) binary NOT NULL default '',
web varchar(60) binary default NULL,
dfstocks varchar(60) binary NOT NULL default '',
dftypes varchar(60) binary NOT NULL default '',
details blob binary NOT NULL default '',
optin varchar(5) binary NOT NULL default ''
) TYPE=MyISAM;
This is the code used in the form processor to insert values into the database:
// CONNECT TO MYSQL DB //
// OPEN CONNECTION --->
$connection=mysql_connect(
"localhost
", "dbuser", "dbpass") or die("Unable to connect!");
mysql_select_db("dbname") or die("Unable to select database!");
$dfstocks=serialize($_POST
['dfstocks
']);
$dftypes=serialize($_POST[
'dftypes']
);
// EXECUTE QUERY --->
$query="INSERT INTO getListed (
firstname,
lastname,
bizname,
street,
city,
county,
postcode,
phone,
email,
web,
dfstocks,
dftypes,
details,
optin)
VALUES(
'".$firstname."',
'".$lastname."',
'".$bizname."',
'".$street."',
'".$city."',
'".$county."',
'".$postcode."',
'".$phone."',
'".$email."',
'".$web."',
'".$dfstocks."',
'".$dftypes."',
'".$details."',
'".$optin."')";
All values are inserted correctly except the two arrays: dfstocks and dftypes, which appears in the database as: N;
In the same form processor this is how I'm forming the array:
foreach($_POST["stocks"] as $stocks)
$dfstocks .= "$stocks\n";
foreach($_POST["types"] as $types)
$dftypes .= "$types\n";
Prior to this I check for the existence of $stocks and $types and if values are not present - a form error is returned requiring the user to enter a value.
- How can I get the array values of dftocks and dftypes into the database in the required format?
Thanks.