rowanp Posted April 15, 2005 Posted April 15, 2005 Hi I have created a MySQL database, and am trying to integrate it with a perl script I have written. Everything works up to the line, DBI->execute($sql) or die "Couldn't add to db " . DBI->errstr;. After that there is a blank out. What could be the problem? Here is the script: #!/usr/bin/perl use DBI; print "Content-type: text/html\n\n"; $database="cpanelusername_*******"; $user="cpanelusername_******"; $passworddata="*****"; $host="localhost"; $dbh = DBI->connect("DBI:mysql:$database:localhost","$user","$passworddata") or die "Couldn't connect to database: " . DBI->errstr; if($dbh) { print "Inside the database"; my ($db) = @_; $sql="INSERT into cc_details (date,order_amount,card_num,card_exp_mon,card_exp_year,street1,street2,city,prov,post code,tel_num,bill_email,card_name,order_num) values ('$db{'date'}','$db{'order_amount'}','$db{'card_num'}','$db{'card_exp_mon'}','$db{'card_exp_year'}','$db{'street1'}','$db{'street2'}','$db{'city'}','$db{'prov'}','$db{'post_code'}','$db{'tel_num'}','$db{'bill_email'}','$db{'card_name'}','$db{'order_num'}')"; DBI->execute($sql) or die "Couldn't add to db " . DBI->errstr; } Quote
TweezerMan Posted April 15, 2005 Posted April 15, 2005 The browser page is blank because you are not printing any output to the browser (other than the Content-Type header). If an error occurs when the query is executed, the 'die' statement message will be sent to the web server error log instead of the browser window. You'll need to look at the Error Log in your CPanel to see what the error message is. Quote
TweezerMan Posted April 15, 2005 Posted April 15, 2005 I forgot about this statement: >print "Inside the database"; I still think you should check the Error Log and see if any messages are recorded there. Quote
TweezerMan Posted April 15, 2005 Posted April 15, 2005 There's a few problems with the script as you currently have it: 1) You're missing a comma at the end of the first line of your $sql query string (you need a comma after 'post'). 2a) You need to execute your query and error methods ('errstr') with your database connection object ($dbh) instead of calling it on the DBI class. 2b) If you're not going to 'prepare' your SQL query, you need to use the 'do' method to run it instead of the 'execute' method. This line: >DBI->execute($sql) or die "Couldn't add to db " . DBI->errstr; ...should be written like this: >$dbh->do($sql) or die "Couldn't add to db: " . $dbh->errstr; Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.