Say I have a table with 1 field "question".
I have a form with two text boxes. The first question[0] and the second question[1]. How will I be able to insert each text box entry as a new row via the insert mysql statement?
| SitePoint Sponsor |

Say I have a table with 1 field "question".
I have a form with two text boxes. The first question[0] and the second question[1]. How will I be able to insert each text box entry as a new row via the insert mysql statement?
Bardius





try this out.
i use to using something like this in C. Should still apply. After you get the values into $insert_value1, 2, 3 etc... you can just insert each value into your database.PHP Code:for($i=0; $i<2; $i++)
{
$insert_value . $i = $question[$i];
$insert_value . $i = $question[$i];
}
I would just do this for the sake of extra code else where (then if the # of Qs grows use the for statements to build the inserts the insert them)
Thats my thoughts.PHP Code:
for($i=0; $i< count($question); $i++) // the count($question) should make it loop until all question[x]s that exist have been inserted.
{
$insert_value = @mysql_query("INSERT INTO $tblname (Qcol)VALUES ('$question[$i]')");
// or remove the @ to see errors (seeing errors is nice for debugging)
}
Microsoft's Motto: Resistance is futile, you will be assimilated.
My dog's name is Jade; she is a Miniature pinscher.
Click here to see some of her pictures
Use serialize():
http://www.php.net/manual/en/function.serialize.php
Sean
Harry Potter
-- You lived inside my world so softly
-- Protected only by the kindness of your nature





serialize() goes against the purpose of a relational database here. By storing each question as a new record in the database, you not only will have easier access to the questions, you will be following a more efficient method of storing the data.
Please don't PM me with questions.
Use the forums, that is what they are here for.
Bookmarks