For one, as you've written it you have a mismatch of columns vs. fields -- You're combining id and name into one field for the insert -- thus you have five fields trying to be inserted into a table with six elemets. You should have a print of the mysql_error() in your debug code ... I bet if you did that's what it would tell you:) On Sun, Jul 15, 2001 at 07:17:00AM -0600, David wrote: > I am trying to insert an array of rows or values from a PHP form into a > MySQL database. There are six columns in the table songs: id, songname, > rating, video, album_id, movie. > > Here is what I get when I submit the form > Add songs for Record Array > INSERT INTO songs VALUES (' 1, blah', ' ***', ' 45', ' 2', ' ') > id[0]=: 2 this is debug code > INSERT Failed, check the code......... this is debug code > > The problem seems to be with this part: > > for ($i=0; $i<= $songsinalbum; $i++) { > $vals .=", ('$id[$i], $songname[$i]', '$rating[$i]', '$video[$i]', > '$album_id[$i]', > '$movie[$i]')"; > } > > // $vals=preg_replace("^,", "", $vals); > $vals=preg_replace('/^,/', '', $vals); // chop leading comma > > > Complete code: > When the user presses submit on the form this part executes: > > mysql_connect("192.168.0.1", "mysqluser", "mypassword"); > > $vals=' '; > for ($i=0; $i<= $songsinalbum; $i++) { > $vals .=", ('$id[$i], $songname[$i]', '$rating[$i]', '$video[$i]', > '$album_id[$i]', > '$movie[$i]')"; > } > > // $vals=preg_replace("^,", "", $vals); > $vals=preg_replace('/^,/', '', $vals); // chop leading comma > > $qry="INSERT INTO songs VALUES $vals"; > > echo $qry; > > $res=mysql_query($qry); > > > Here is part of the form: > > <? > $i = 1; > while ($i <= $songsinalbum) { > ?> > > <TD align="right">ID: </TD><TD><input type=text name=id[] > size=3><br></TD> > > <TD align="right">Songname: </TD><TD><input type=text name=songname[] > size=30><br></TD> > <? > $i++; > }; > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] -- Hank Marquardt <[EMAIL PROTECTED]> http://web.yerpso.net Web & Database Development in PHP, MySQL/PostgreSQL Small Office Networking Solutions - Debian GNU/Linux & FreeBSD PHP Instructor - HTML Writers Guild <http://www.hwg.org> *** PHP II "The Cool Stuff" starts July 16, 2001 *** http://www.hwg.org/services/classes/p181.1.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]