Jump to content

Recommended Posts

Posted

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;

}

Posted

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.

Posted

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;

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...