On Saturday 03 November 2001 04:26, paco anubis wrote: > Hello, > I started learning Perl 4 weeks ago and mysql 3 days > ago so I know that I am in over my head, but here goes > nothing. I am trying to build a Perl CGI application > (using DBI) to pass form contents from a web page > directly into a MySql database. > I don't know how to pass the Perl variable from the > form into the database. I tried to assign the value > using the following code (where "$feilds{user}" is the > Perl variable to pass): > > $userdb=$dbh->($feilds{user}); > > $rows=$dbh->do > ("INSERT INTO bandbook (user, ect, ect...) > VALUES ($userdb, 'ect', 'ect', ...)") > > || die "fucked up inserting data: $DBI::errstr"; > > print "$rows row succesfully added to bandbook\n"; > > > As you may have guessed the table, bandbook is still > empty because the script always dies. Can anyone point > me in a better direction. Due to my unfamiliarity with > either language, I am definately not ruling out a > syntax error.
It's good practice to assign your SQL query to a variable which you can then print out for debugging purposes. It also allows you to copy and paste that query into mysql directly and see what results it yields. I think your problem is that you haven't quoted the VALUES that you're inserting. Try: $QRY = "INSERT INTO bandbook (user, ect1, ect2...) VALUES ('$userdb', '$ect1', '$ect2', ...)"; print("$QRY"); ## For debugging $rows=$dbh->do($QRY) || die "Error"; hth -- Jason Wong Gremlins Associates www.gremlins.com.hk --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <mysql-unsubscribe-##L=##[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php