Jump to content

Retrieving data from listbox and inserting into DB


gopichand

Recommended Posts


am using a list box in the front end and the user selects more than one option from the list box..all these options must go into a single column in a table of the datbase..only one value is getting inserted into the column with the query here and moreover it is generating an error ..How to insert all the selected values into a single dabatase column,I hope u understood this?


$query = "INSERT INTO tutorials (uid, name, dname, cname, date, description, Keywords, SLO) VALUES ('" . $user . "','" . $name . "','" . $dname . "','" . $cname . "','" . $date \
. "','" . $description . "','" . $_POST['Keywords'] . "','" . join("'), ('", $_POST['name_here']) . "')";

This query is generating the following error

INSERT INTO tutorials (uid, name, dname, cname, date, description, Keywords, SLO) VALUES ('22','akkf','kajfkafka','kasjfk','1157560060','kdfakf','fjakfaj','9'), ('8'), ('7')Column count doesn't match value count at row 2

How to solve this problem?
Link to comment
Share on other sites

Here you are specifying which columns you are inserting values for, 8 of them.
INSERT INTO tutorials (uid, name, dname, cname, date, description, Keywords, SLO)

Here is your first set of values, 8 of them
('22','akkf','kajfkafka','kasjfk','1157560060','kdfakf','fjakfaj','9'),

Here is your second set of values, 1 value
('8'),

If you tell MySQL you are inserting into 8 columns, you have to insert 8 values for every row.
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.