将HTML上传到数据库 - PERL

时间:2010-02-07 07:42:34

标签: mysql html perl

我试图将HTML上传到数据库中,该数据库对某些文件有效但不是全部。

my $fileContents;
if( $md5Con =~ m/\.php$/g ) {
    my $ftp = Net::FTP->new($DB_ftpserver, Debug => 0) or die "Cannot connect to some.host.name: $@";
    $ftp->login($DB_ftpuser, $DB_ftppass) or die "Cannot login ", $ftp->message;
    ftp->get("/" . $root . $webpage, "c:/perlscripts/" . md5_hex($md5Con) . "-code.php") or die $ftp->message;
    my $file = "c:/perlscripts/" . md5_hex($md5Con) . "-code.php";
    {
       local( $/ ); # undefine the record seperator
       open FILE, "<", $file or die "Cannot open:$!\n";
       my $fileContents = <FILE>;
       #print $fileContents;
       my $bodyContents;
       my $headContents;

       my @contentsArray = split( /<\/head>/is, $fileContents, 2);

       if( scalar @contentsArray == 2 ){
           $bodyContents = $dbh->quote(trim($contentsArray[1]));
           $headContents = $dbh->quote(trim($contentsArray[0]) . "</head>");

           $dbh->do($createBodyTable) or die " error: Couldn't create body table: " . DBI->errstr;
           $dbh->do($createHeadTable) or die " error: Couldn't create header table: " . DBI->errstr;
           $dbh->do("INSERT INTO $headerTable ( headData, headDataOutput ) VALUES ( $headContents, $headContents )") or die " error: Couldn't connect to database: " . DBI->errstr;
           $dbh->do("INSERT INTO $bodyTable ( bodyData, bodyDataOutput ) VALUES ( $bodyContents, $bodyContents )") or die " error: Couldn't connect to database: " . DBI->errstr;
           $dbh->do("INSERT INTO page_names (linkFromRoot, linkTrue, page_name, table_name, navigation, location) VALUES ( $linkFromRoot, $linkTrue, $page_name, $table_name, $navigation, $location )") or die " error: Couldn't connect to database: " . DBI->errstr;

           unlink("c:/perlscripts/" . md5_hex($md5Con) . "-code.php");
       }else{
           print "<span class=\"red\">" . $md5Con . " cannot be used by our CMS, invalid data.</span><br />\n";
       }
   }
   $ftp->quit;
}

谁能明白为什么会发生这种情况?

修改

要以不同的角度看,这是进入数据库的数据的输出......前三个代码块完全没有,然后是第四个的错误。

<span class="green">http://www.themobilemakeover.co.uk/index.php</span><br />

'<?php session_start(); ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"h
ttp://www.w3.org/1999/xhtml\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n<meta name=\"description\" content=\"The Mo
bile Makeover offers a wide range of services and treatments all from the luxuary of your own home!\" />\n<meta name=\"keywords\" content=\"Mobile Makeover, B
eauty Therapist, Beautician, Therapist, Mobile Therapist, Mansfield, Nottinghamshire\" />\n<meta name=\"language\" content=\"en\" />\n<meta name=\"author\" co
ntent=\"ACT Web Designs\" />\n<meta name=\"copyright\" content=\"The Mobile Makeover\" />\n<meta name=\"publisher\" content=\"ACT Web Designs\" />\n<meta name
=\"country\" content=\"United Kingdom\" />\n<meta name=\"city\" content=\"Mansfield, Nottinghamshire\" />\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=8
\" /> \n<meta name=\"verify-v1\" content=\"4lZIaMmjLMq+UA8nkPYB9RjF5RreNwF3Mzurm9JYvQM=\" />\n<title>The Mobile Makeover - Mobile Beautician</title>\n<link hr
ef=\"stylesheets/main.css\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"stylesheets/cssReset.css\" rel=\"stylesheet\" type=\"text/css\" />\n<script
type=\"text/javascript\" src=\"js/jquery-1.3.1.js\"></script>\n<script type=\"text/javascript\" src=\"js/jquery.bgpos.js\"></script>\n<script type=\"text/java
script\" src=\"js/jquery.timers.js\"></script>\n<script type=\"text/javascript\" src=\"js/makeover.scroll.js\"></script>\n<script type=\"text/javascript\">\nv
ar gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\ndocument.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"
google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));\n</script>\n<script type=\"text/javascript\">\ntry {\nvar pageTracker = _gat._getTr
acker(\"UA-8193659-6\");\npageTracker._trackPageview();\n} catch(err) {}</script></head>'

<span class="green">http://www.themobilemakeover.co.uk/about-us-the-mobile-makeover.php</span><br />

'<?php session_start(); ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"h
ttp://www.w3.org/1999/xhtml\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n<meta name=\"description\" content=\">My na
me is Kelly Knight, I am a highly Qualifed Mobile Beauty Therapist. I have trained in NVQ Level 2 and NVQ level 3 in Beauty Therapy with many additional cours
es and training...\" />\n<meta name=\"keywords\" content=\"Mobile Makeover, About Us, Beauty Therapist, Mobile Therapist, Mansfield, Nottinghamshire\" />\n<me
ta name=\"language\" content=\"en\" />\n<meta name=\"author\" content=\"ACT Web Designs\" />\n<meta name=\"copyright\" content=\"The Mobile Makeover\" />\n<me
ta name=\"publisher\" content=\"ACT Web Designs\" />\n<meta name=\"country\" content=\"United Kingdom\" />\n<meta name=\"city\" content=\"Mansfield, Nottingha
mshire\" />\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\" /> \n<title>The Mobile Makeover - About Us</title>\n<link href=\"stylesheets/main.css\" rel
=\"stylesheet\" type=\"text/css\" />\n<link href=\"stylesheets/cssReset.css\" rel=\"stylesheet\" type=\"text/css\" />\n<script type=\"text/javascript\" src=\"
js/jquery-1.3.1.js\"></script>\n<script type=\"text/javascript\" src=\"js/jquery.bgpos.js\"></script>\n<script type=\"text/javascript\" src=\"js/jquery.timers
.js\"></script>\n<script type=\"text/javascript\" src=\"js/makeover.scroll.js\"></script>\n<script type=\"text/javascript\">\nvar gaJsHost = ((\"https:\" == d
ocument.location.protocol) ? \"https://ssl.\" : \"http://www.\");\ndocument.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' ty
pe=\'text/javascript\'%3E%3C/script%3E\"));\n</script>\n<script type=\"text/javascript\">\ntry {\nvar pageTracker = _gat._getTracker(\"UA-8193659-6\");\npageT
racker._trackPageview();\n} catch(err) {}</script></head>'

<span class="green">http://www.themobilemakeover.co.uk/beauty-products-used.php</span><br />

'<?php session_start(); ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"h
ttp://www.w3.org/1999/xhtml\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n<meta name=\"description\" content=\"We use
 a wide range of the finest products on the market today. Below is a short brief of just a few of the names which we believe give you the best results - we do
 not compromise when it comes to quality.\" />\n<meta name=\"keywords\" content=\"Mobile Makeover, Beauty Therapist, Beauty Products, Jessica, Calgel, Eve Tay
lor, Tantrick, Therapist, Mansfield, Nottinghamshire\" />\n<meta name=\"language\" content=\"en\" />\n<meta name=\"author\" content=\"ACT Web Designs\" />\n<m
eta name=\"copyright\" content=\"The Mobile Makeover\" />\n<meta name=\"publisher\" content=\"ACT Web Designs\" />\n<meta name=\"country\" content=\"United Ki
ngdom\" />\n<meta name=\"city\" content=\"Mansfield, Nottinghamshire\" />\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\" /> \n<title>The Mobile Makeov
er - Beauty Products Used</title>\n<link href=\"stylesheets/main.css\" rel=\"stylesheet\" type=\"text/css\" />\n<link href=\"stylesheets/cssReset.css\" rel=\"
stylesheet\" type=\"text/css\" />\n<!--[if lte IE 6]><link href=\"stylesheets/mainie6.css\" rel=\"stylesheet\" type=\"text/css\" /><![endif]-->\n<script type=
\"text/javascript\" src=\"js/jquery-1.3.1.js\"></script>\n<script type=\"text/javascript\" src=\"js/jquery.bgpos.js\"></script>\n<script type=\"text/javascrip
t\" src=\"js/jquery.timers.js\"></script>\n<script type=\"text/javascript\" src=\"js/makeover.scroll.js\"></script>\n<script type=\"text/javascript\">\nvar ga
JsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\ndocument.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"googl
e-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"));\n</script>\n<script type=\"text/javascript\">\ntry {\nvar pageTracker = _gat._getTracker
(\"UA-8193659-6\");\npageTracker._trackPageview();\n} catch(err) {}</script></head>'

<span class="green">http://www.themobilemakeover.co.uk/beauty-treatments.php</span><br />

'<?php session_start(); ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html xmlns=\"h
ttp://www.w3.org/1999/xhtml\">\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n<meta name=\"description\" content=\"The Mo
bile Makeover offers a wide range of treatments all from the luxuary of your own home!\" />\n<meta name=\"keywords\" content=\"Mobile Makeover, Beauty Treatme
nts, Beautician, Facials, Pedicures, Hopi Ear Candles, Eye Treatments, Mansfield, Nottinghamshire\" />\n<meta name=\"language\" content=\"en\" />\n<meta name=
\"author\" content=\"ACT Web Designs\" />\n<meta name=\"copyright\" content=\"The Mobile Makeover\" />\n<meta name=\"publisher\" content=\"ACT Web Designs\" /
>\n<meta name=\"country\" content=\"United Kingdom\" />\n<meta name=\"city\" content=\"Mansfield, Nottinghamshire\" />\n<meta http-equiv=\"X-UA-Compatible\" c
ontent=\"IE=8\" /> \n<title>The Mobile Makeover - Beauty Treatments</title>\n<link href=\"stylesheets/main.css\" rel=\"stylesheet\" type=\"text/css\" />\n<lin
k href=\"stylesheets/cssReset.css\" rel=\"stylesheet\" type=\"text/css\" />\n<script type=\"text/javascript\" src=\"js/jquery-1.3.1.js\"></script>\n<script ty
pe=\"text/javascript\" src=\"js/jquery.bgpos.js\"></script>\n<script type=\"text/javascript\" src=\"js/jquery.timers.js\"></script>\n<script type=\"text/javas
cript\" src=\"js/makeover.scroll.js\"></script>\n<script type=\"text/javascript\">\nvar gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl
.\" : \"http://www.\");\ndocument.write(unescape(\"%3Cscript src=\'\" + gaJsHost + \"google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E\"))
;\n</script>\n<script type=\"text/javascript\">\ntry {\nvar pageTracker = _gat._getTracker(\"UA-8193659-6\");\npageTracker._trackPageview();\n} catch(err) {}<
/script></head>'


DBD::mysql::db do failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use nea
r '22e64cef7d70fa952ce7444f158e2c4e_header ( headData, headDataOutput ) VALUES ( '<' at line 1 at C:\perlscripts\cgitest.pl line 360, <FILE> chunk 4.

 error: Couldn't connect to database: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right synta
x to use near '22e64cef7d70fa952ce7444f158e2c4e_header ( headData, headDataOutput ) VALUES ( '<' at line 1 at C:\perlscripts\cgitest.pl line 360, <FILE> chunk
 4.

&GT;&GT;&GT;&GT;&GT;&GT;编辑2&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;

使用追踪后,我不是更聪明的人。这是我的日志:

(现在删除“quote()”并使用占位符)

    DBI 1.607-ithread default trace level set to 0x0/1 (pid 13524) at cgitest.pl line 10
    -> DBI->connect(*****************************************************)
    -> DBI->install_driver(mysql) for MSWin32 perl=5.010001 pid=13524 ruid=0 euid=0
       install_driver: DBD::mysql version 4.011 loaded from C:/Perl/site/lib/DBD/mysql.pm
    <- install_driver= DBI::dr=HASH(0x37be1fc)
    !! warn: 0 CLEARED by call to connect method
    <- connect('database=web110-accounts;host=79.170.44.110;', 'web110-accounts', ...)= DBI::db=HASH(0x37bdc8c) at DBI.pm line 638
    <- STORE('PrintError', 1)= 1 at DBI.pm line 690
    <- STORE('AutoCommit', 1)= 1 at DBI.pm line 690
    <- STORE('Username', 'web110-accounts')= 1 at DBI.pm line 693
    <> FETCH('Username')= 'web110-accounts' ('Username' from cache) at DBI.pm line 693
    <- connected(**********************************)= undef at DBI.pm line 699
    <- connect= DBI::db=HASH(0x37bdc8c)
    <- STORE('dbi_connect_closure', CODE(0x37c3634))= 1 at DBI.pm line 708
    <- prepare('SELECT * FROM accounts WHERE KI = '9096699576bcc810df5bc311650c4ebd' ')= DBI::st=HASH(0x37bda24) at cgitest.pl line 61
    <- execute= 1 at cgitest.pl line 62
    <- rows= '1' at cgitest.pl line 63
    <- fetchrow_hashref= HASH(0x37bd514)24keys row1 at cgitest.pl line 64
    <- finish= 1 at cgitest.pl line 71
    <- disconnect= 1 at cgitest.pl line 72
   ****************************************************************************
   ****************************************************************************
    <- STORE('PrintError', 1)= 1 at DBI.pm line 690
    <- STORE('AutoCommit', 1)= 1 at DBI.pm line 690
    <- STORE('Username', 'web110-db-2')= 1 at DBI.pm line 693
    <> FETCH('Username')= 'web110-db-2' ('Username' from cache) at DBI.pm line 693
    <- connected('DBI:mysql:database=web110-db-2;host=79.170.44.110;', 'web110-db-2', ...)= undef at DBI.pm line 699
    <- connect= DBI::db=HASH(0x3d615ac)
    <- STORE('dbi_connect_closure', CODE(0x3d60f6c))= 1 at DBI.pm line 708
    <- prepare('INSERT INTO ? ( headData, headDataOutput ) VALUES ( ?, ? )')= DBI::st=HASH(0x351659c) at cgitest.pl line 263
    <- prepare('INSERT INTO ? ( bodyData, bodyDataOutput ) VALUES ( ?, ? )')= DBI::st=HASH(0x37bd914) at cgitest.pl line 264
    <- prepare('INSERT INTO page_names (linkFromRoot, linkTrue, page_name, table_name, navigation, location) VALUES ( ?, ?, ?, ?, ?, ? )')= DBI::st=HASH(0x3d575fc) at cgitest.pl line 265
    <- quote("http://www.themobilemakeover.co.uk/index.php")= "'http://www.themobilemakeover.co.uk/index.php'" at cgitest.pl line 271
    <- prepare("SELECT * FROM page_names WHERE linkTrue = 'http://www.themobilemakeover.co.uk/index.php' ")= DBI::st=HASH(0x3d571bc) at cgitest.pl line 272
    <- execute= '0E0' at cgitest.pl line 273
    <- rows= '0' at cgitest.pl line 274
    <- quote("The Mobile Makeover - Mobile Beautician")= "'The Mobile Makeover - Mobile Beautician'" at cgitest.pl line 289
    <- prepare("SELECT * FROM page_names WHERE page_name = 'The Mobile Makeover - Mobile Beautician' ")= DBI::st=HASH(0x3d56fdc) at cgitest.pl line 290
    <- execute= '0E0' at cgitest.pl line 291
    <- rows= '0' at cgitest.pl line 292
    <- DESTROY(DBI::st=HASH(3d54254))= undef at cgitest.pl line 287
    <- do('CREATE TABLE IF NOT EXISTS `6959bbd13fdb4df586a5b9d08aae1153_body` (
                    `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                    `bodyData` TEXT NOT NULL, 
                    `bodyDataOutput` TEXT NOT NULL 
                    ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')= '0E0' at cgitest.pl line 362
    <- do('CREATE TABLE IF NOT EXISTS `6959bbd13fdb4df586a5b9d08aae1153_header` (
                    `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                    `headData` TEXT NOT NULL, 
                    `headDataOutput` TEXT NOT NULL 
                    ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')= '0E0' at cgitest.pl line 363
    !! ERROR: 1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''6959bbd13fdb4df586a5b9d08aae1153_header' ( headData, headDataOutput ) VALUES ( ' at line 1' (err#0)
    <- execute('6959bbd13fdb4df586a5b9d08aae1153_header', '<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="The Mobile Makeover offers a wide range of services and treatments all from the luxuary of your own home!" />
<meta name="keywords" content="Mobile Makeover, Beauty Therapist, Beautician, Therapist, Mobile Therapist, Mansfield, Nottinghamshire" />
<meta name="language" content="en" />
<meta name="author" content="ACT Web Designs" />
<meta name="copyright" content="The Mobile Makeover" />
<meta name="publisher" content="ACT Web Designs" />
<meta name="country" content="United Kingdom" />
<meta name="city" content="Mansfield, Nottinghamshire" />
<meta http-equiv="X-UA-Compatible" content="IE=8" /> 
<meta name="verify-v1" content="4lZIaMmjLMq+UA8nkPYB9RjF5RreNwF3Mzurm9JYvQM=" />
<title>The Mobile M...', ...)= undef at cgitest.pl line 365
    !! ERROR: 1064 CLEARED by call to execute method
    !! ERROR: 1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''6959bbd13fdb4df586a5b9d08aae1153_body' ( bodyData, bodyDataOutput ) VALUES ( '<' at line 1' (err#0)
    <- execute('6959bbd13fdb4df586a5b9d08aae1153_body', '<body>
    <div id="wrapper">
        <div id="header">
            <div id="innerHeader">
                <h1><span>The Mobile Makeover - Mobile Beauty Therapist - Mansfield Nottinghamshire</span></h1>
                <div class="clear"></div>
                <?php include("php/navigation.php"); ?>
                <div class="clear"></div>
            </div>
        </div>
        <div id="main">
            <div id="content1" class="content vis">
                <h2>Welcome to The Mobile Makeover</h2>
                <div class="image1">
                </div>
                <p>Home visit appointments are designed to save you time and stress, by providing a service in the comfort of your own home, no need to worry about travel and traffic or facing the cold night air after a relaxing treatment.</p>
                <p>If you have a baby or a toddler The Mobile Makeover can help you put together a package of <a href="beauty-treatments.php" title="link to treatments page">treatments</a> that is ada...', ...)= undef at cgitest.pl line 366
    !! ERROR: 1064 CLEARED by call to execute method
    <- execute("public_html/index.php", "http://www.themobilemakeover.co.uk/index.php", ...)= 1 at cgitest.pl line 367
    <- DESTROY(DBI::st=HASH(3d56f5c))= undef at cgitest.pl line 270
    <- quote("http://www.themobilemakeover.co.uk/about-us-the-mobile-makeover.php")= "'http://www.themobilemakeover.co.uk/about-us-the-mobile-makeover.php'" at cgitest.pl line 271
    <- prepare("SELECT * FROM page_names WHERE linkTrue = 'http://www.themobilemakeover.co.uk/about-us-the-mobile-makeover.php' ")= DBI::st=HASH(0x3d56d9c) at cgitest.pl line 272
    <- execute= '0E0' at cgitest.pl line 273
    <- rows= '0' at cgitest.pl line 274
    <- quote("The Mobile Makeover - About Us")= "'The Mobile Makeover - About Us'" at cgitest.pl line 289
    <- prepare("SELECT * FROM page_names WHERE page_name = 'The Mobile Makeover - About Us' ")= DBI::st=HASH(0x3b07814) at cgitest.pl line 290
    <- execute= '0E0' at cgitest.pl line 291
    <- rows= '0' at cgitest.pl line 292
    <- DESTROY(DBI::st=HASH(3d54254))= undef at cgitest.pl line 287
    <- do('CREATE TABLE IF NOT EXISTS `30df18a64311aa9aaaa9576b030f0f83_body` (
                    `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                    `bodyData` TEXT NOT NULL, 
                    `bodyDataOutput` TEXT NOT NULL 
                    ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')= '0E0' at cgitest.pl line 362
    <- do('CREATE TABLE IF NOT EXISTS `30df18a64311aa9aaaa9576b030f0f83_header` (
                    `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                    `headData` TEXT NOT NULL, 
                    `headDataOutput` TEXT NOT NULL 
                    ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')= '0E0' at cgitest.pl line 363
    !! ERROR: 1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''30df18a64311aa9aaaa9576b030f0f83_header' ( headData, headDataOutput ) VALUES ( ' at line 1' (err#0)
    <- execute('30df18a64311aa9aaaa9576b030f0f83_header', '<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content=">My name is Kelly Knight, I am a highly Qualifed Mobile Beauty Therapist. I have trained in NVQ Level 2 and NVQ level 3 in Beauty Therapy with many additional courses and training..." />
<meta name="keywords" content="Mobile Makeover, About Us, Beauty Therapist, Mobile Therapist, Mansfield, Nottinghamshire" />
<meta name="language" content="en" />
<meta name="author" content="ACT Web Designs" />
<meta name="copyright" content="The Mobile Makeover" />
<meta name="publisher" content="ACT Web Designs" />
<meta name="country" content="United Kingdom" />
<meta name="city" content="Mansfield, Nottinghamshire" />
<meta http-equiv="X-UA-Compatible" content="IE=8" /> 
<title>The Mobile Makeover - About U...', ...)= undef at cgitest.pl line 365
    !! ERROR: 1064 CLEARED by call to execute method
    !! ERROR: 1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''30df18a64311aa9aaaa9576b030f0f83_body' ( bodyData, bodyDataOutput ) VALUES ( '<' at line 1' (err#0)
    <- execute('30df18a64311aa9aaaa9576b030f0f83_body', '<body id="aboutUsPage">
    <div id="wrapper">
        <div id="header">
            <div id="innerHeader">
                <h1><span>The Mobile Makeover - About Us</span></h1>
                <div class="clear"></div>
                <?php include("php/navigation.php"); ?>
                <div class="clear"></div>
            </div>
        </div>
        <div id="main">
            <div id="content1" class="content vis">
                <h2>About Us - Kelly Night</h2>
                <div class="image1">
                </div>
                <p>My name is Kelly Knight, I am a highly Qualified Mobile Beauty Therapist. I have trained in NVQ Level 2 and NVQ level 3 in Beauty Therapy with many additional courses and training gained within my time in the beauty industry. I have gained my years of experience from working at one of the UK's biggest Hotels &amp; Spa chains where i worked as a salon supervisor. After being approached by a number of people to go mobile to their homes i recognised that the...', ...)= undef at cgitest.pl line 366
    !! ERROR: 1064 CLEARED by call to execute method
    <- execute("public_html/about-us-the-mobile-makeover.php", "http://www.themobilemakeover.co.uk/about-us-the-mobile-makeover.php", ...)= 1 at cgitest.pl line 367
    <- DESTROY(DBI::st=HASH(3d56f1c))= undef at cgitest.pl line 270
    <- quote("http://www.themobilemakeover.co.uk/beauty-products-used.php")= "'http://www.themobilemakeover.co.uk/beauty-products-used.php'" at cgitest.pl line 271
    <- prepare("SELECT * FROM page_names WHERE linkTrue = 'http://www.themobilemakeover.co.uk/beauty-products-used.php' ")= DBI::st=HASH(0x3d56f3c) at cgitest.pl line 272
    <- execute= '0E0' at cgitest.pl line 273
    <- rows= '0' at cgitest.pl line 274
    <- quote("The Mobile Makeover - Beauty Products Used")= "'The Mobile Makeover - Beauty Products Used'" at cgitest.pl line 289
    <- prepare("SELECT * FROM page_names WHERE page_name = 'The Mobile Makeover - Beauty Products Used' ")= DBI::st=HASH(0x3d545a4) at cgitest.pl line 290
    <- execute= '0E0' at cgitest.pl line 291
    <- rows= '0' at cgitest.pl line 292
    <- DESTROY(DBI::st=HASH(3d54684))= undef at cgitest.pl line 287
    <- do('CREATE TABLE IF NOT EXISTS `02b5f135f611c1d7b0ec090182bc6cf5_body` (
                    `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                    `bodyData` TEXT NOT NULL, 
                    `bodyDataOutput` TEXT NOT NULL 
                    ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')= '0E0' at cgitest.pl line 362
    <- do('CREATE TABLE IF NOT EXISTS `02b5f135f611c1d7b0ec090182bc6cf5_header` (
                    `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                    `headData` TEXT NOT NULL, 
                    `headDataOutput` TEXT NOT NULL 
                    ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_general_ci;')= '0E0' at cgitest.pl line 363
    !! ERROR: 1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''02b5f135f611c1d7b0ec090182bc6cf5_header' ( headData, headDataOutput ) VALUES ( ' at line 1' (err#0)
    <- execute('02b5f135f611c1d7b0ec090182bc6cf5_header', '<?php session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="We use a wide range of the finest products on the market today. Below is a short brief of just a few of the names which we believe give you the best results - we do not compromise when it comes to quality." />
<meta name="keywords" content="Mobile Makeover, Beauty Therapist, Beauty Products, Jessica, Calgel, Eve Taylor, Tantrick, Therapist, Mansfield, Nottinghamshire" />
<meta name="language" content="en" />
<meta name="author" content="ACT Web Designs" />
<meta name="copyright" content="The Mobile Makeover" />
<meta name="publisher" content="ACT Web Designs" />
<meta name="country" content="United Kingdom" />
<meta name="city" content="Mansfield, Nottinghamshire" />
<meta http-equiv="X-UA-Compa...', ...)= undef at cgitest.pl line 365
    !! ERROR: 1064 CLEARED by call to execute method
    !! ERROR: 1064 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''02b5f135f611c1d7b0ec090182bc6cf5_body' ( bodyData, bodyDataOutput ) VALUES ( '<' at line 1' (err#0)
    <- execute('02b5f135f611c1d7b0ec090182bc6cf5_body', '<body id="aboutUsPage">
    <div id="wrapper">
        <div id="header">
            <div id="innerHeader">
                <h1><span>The Mobile Makeover - Beauty Products</span></h1>
                <div class="clear"></div>
                <?php include("php/navigation.php"); ?>
                <div class="clear"></div>
            </div>
        </div>
        <div id="main">
            <div id="content1" class="content vis">
                <h2>Beauty products that we use</h2>
                <div class="image1">
                </div>
                <p>We use a wide range of the finest products on the market today. Below is a short brief of just a few of the names which we believe give you the best results - we do not compromise when it comes to quality.<br /> - <em>Kelly Knight</em></p>
            </div>
            <div class="content vis norm">
                <h2>Jessica</h2>
                <div class="image3">
                </div>
                <p>The Jessica &copy; nail products are de...', ...)= undef at cgitest.pl line 366
    !! ERROR: 1064 CLEARED by call to execute method
    <- execute("public_html/beauty-products-used.php", "http://www.themobilemakeover.co.uk/beauty-products-used.php", ...)= 1 at cgitest.pl line 367
    <- DESTROY(DBI::st=HASH(3d6982c))= undef at cgitest.pl line 270
    <- quote("http://www.themobilemakeover.co.uk/beauty-treatments.php")= "'http://www.themobilemakeover.co.uk/beauty-treatments.php'" at cgitest.pl line 271
    <- prepare("SELECT * FROM page_names WHERE linkTrue = 'http://www.themobilemakeover.co.uk/beauty-treatments.php' ")= DBI::st=HASH(0x3d56edc) at cgitest.pl line 272
    <- execute= '0E0' at cgitest.pl line 273
    <- rows= '0' at cgitest.pl line 274
    <- quote("The Mobile Makeover - Beauty Treatments")= "'The Mobile Makeover - Beauty Treatments'" at cgitest.pl line 289
    <- prepare("SELECT * FROM page_names WHERE page_name = 'The Mobile Makeover - Beauty Treatments' ")= DBI::st=HASH(0x3d6b48c) at cgitest.pl line 290
    <- execute= '0E0' at cgitest.pl line 291
    <- rows= '0' at cgitest.pl line 292
    <- DESTROY(DBI::st=HASH(3d6c674))= undef at cgitest.pl line 287
    <- do('CREATE TABLE IF NOT EXISTS `22e64cef7d70fa952ce7444f158e2c4e_body` (
                    `id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
                    `bodyData` TEXT NOT NULL, 

1 个答案:

答案 0 :(得分:3)

很难确定出现了什么问题,但我认为Andreas Bonini对你引用问题是正确的。

但是,他不小心将你推荐给PHP函数; - )

您可以使用DBI的 quote method 获得相同的效果。 (更新: oops ,你已经将它用于数据项。但是你也可能需要使用它 - 或者占位符 - 用于表名变量吗?)

但是,大多数人认为使用 placeholder values 更好的做法:

while (something) {
    # I've imagined you're looping over the data

    $dbh->do("INSERT INTO $headerTable ( headData, headDataOutput ) 
      VALUES ( $headContents, $headContents )")
        or die " error: Couldn't connect to database: " . DBI->errstr;
}

变为:

my $sth = $dbh->prepare("INSERT INTO ? ( headData, headDataOutput ) 
                  VALUES ( ?, ? )") 
                    or die " error: Couldn't prepare : " . DBI->errstr;)

# later...
while (something) {
    # loop over the data

    $sth->execute($headerTable, $headContents, $headContents) 
      or die "couldn't execute: " . $sth->errstr;
}

未经测试...对不起; - )

我不是100%确定你可以使用占位符来表名,但我不明白为什么不这样做,所以我建议尝试一下。如果没有,你应该引用()表名,如上所述。

假设您的代码在循环中运行,您可以在循环外部准备语句处理程序($ sth)并多次运行execute,如果您有许多插入操作,这应该可以节省一些时间。

HTH