If you are doing lots of similar sql statements, you could use the following instead:
--- start my $dbh = DBI->connect("DBI:mysql:database=prepaid;host=localhost", "root", "sascha28", {'RaiseError' => 1}); my $sql=qq{ INSERT INTO pins (pin, msisdn, value, knd) VALUES ( ?, ?, ?, ?) }; my $sth=$dbh->prepare($sql); while(my $reader = <GENERIERT>) { chomp($reader); print GETESTET "$reader\n"; $sth->execute($reader, 'frei', $wert, $kunde); } # Disconnect from the database. $dbh->disconnect(); --- end This should be faster than many do statements as the SQL needs only be parsed once. It also makes the code slightly cleaner to read. It also gets round the quoting problem. Your actual problem was perhaps: VALUES ($reader, 'frei', $wert, '$kunde') ^^^^^^^ ^^^^^ maybe $reader and $wert were not quoted strings.... M -----Original Message----- From: Amer Neely [mailto:[EMAIL PROTECTED]] Sent: 24 December 2001 15:58 To: MySQL Subject: Re: Perl Problem! > Hi! > > I have a proplem using my perl code to write some data into my mysql > database. When running in consolemode anything works fine, but when > executed by the wwwserver the scripts is processed without errors, > except the data is not written into the database! Any idea how to fixit? > Thanks in advance > Sascha > > PS: the code > > sub generatepins { > > open (GETESTET, ">> /usr/local/httpd/sms/generated.pin"); > open (GENERIERT, "< ./pinanfrage.dat"); > ####db connect und write######## > my $dbh = > DBI->connect("DBI:mysql:database=prepaid;host=localhost", > "root", "sascha28", > {'RaiseError' => 1}); > while(my $reader = <GENERIERT>) > { > chomp($reader); > print GETESTET "$reader\n"; > $dbh->do("INSERT INTO pins (pin, msisdn, value, knd) VALUES > ($reader, 'frei', $wert, '$kunde')"); > } > # Disconnect from the database. > $dbh->disconnect(); > close GENERIERT; > close GETESTET; > > } First try printing your query. I used to use 'do' but switched to the longer method below. It gives you more control over tracing problems I think. Try something like this: mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database"); @mysql_select_db("$DBName") or die("Unable to select database $DBName"); $query=("INSERT INTO pins (pin, msisdn, value, knd) VALUES(\"$reader\", \"frei\", \"$wert\", \"$kunde\")"); # quote everything. singles would work too $result=mysql_query($query); if (!$result) die ("Query 953 failed."); # I use the line number for the Query - easy to find If that doesn't work, print out $query to see what it *really* contains. If your column values are going to be variables, try something like: $last=$dbh->quote("Beck"); $first=$dbh->quote("Jeff"); $query=qq{insert members (last_name,first_name) values ($last,$first); $result=mysql_query($query); Another trick I use for debugging is to put the following at the top of each script: BEGIN { open (STDERR,">>$0-err.txt"); print STDERR "\n",scalar localtime,"\n"; } It merely puts the error messages into a file in the directory the script is running in. That is a lot easier to find than going through server logs. Make sure you comment it out once the script is running well. -- Amer Neely [EMAIL PROTECTED] Softouch Information Services: www.softouch.on.ca/ Perl / PHP / CGI programming for shopping carts, data entry forms. "We make web sites work!" --------------------------------------------------------------------- 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 --------------------------------------------------------------------- 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