[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

Inserting an array into a mysql database

Asked by myrepublic in PHP Scripting Language, MySQL Server

Tags: array, mysql

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.

[+][-]05/09/07 03:16 AM, ID: 19055808Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: PHP Scripting Language, MySQL Server
Tags: array, mysql
Sign Up Now!
Solution Provided By: dancablam
Participating Experts: 2
Solution Grade: A
 
[+][-]05/09/07 03:19 AM, ID: 19055820Assisted Solution

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 30-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05/09/07 03:21 AM, ID: 19055827Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05/09/07 03:23 AM, ID: 19055836Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09/02/07 02:38 PM, ID: 19818158Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09/08/07 09:07 PM, ID: 19855604Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92