Jump to content

Archived

This topic is now archived and is closed to further replies.

gopichand

Retrieving data from listbox and inserting into DB

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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Should that comma be in the front of $POST

          ('"[color=red],[/color] $_POST['name_here']) .

Share this post


Link to post
Share on other sites

×

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.