Jump to content


Photo

Retrieving data from listbox and inserting into DB


  • Please log in to reply
2 replies to this topic

#1 gopichand

gopichand
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 06 September 2006 - 05:31 PM


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?


#2 roopurt18

roopurt18
  • Staff Alumni
  • Advanced Member
  • 3,749 posts
  • LocationCalifornia, southern

Posted 06 September 2006 - 06:14 PM

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.
PHP Forms : Part I | Part II

JavaScript: Singleton

http://www.rbredlau.com

#3 drranch

drranch
  • Members
  • PipPipPip
  • Advanced Member
  • 78 posts

Posted 06 September 2006 - 08:43 PM

Should that comma be in the front of $POST

          ('", $_POST['name_here']) .




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users