CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [wickedxter] Need help writing a script that interacts with a MySQL DB: Edit Log



MDTech.us_MAN
Novice

Sep 30, 2012, 8:15 PM


Views: 13372
Re: [wickedxter] Need help writing a script that interacts with a MySQL DB

OK, thanks wickedxter for your code!

Now I have NEW problems :(

On line 39:

Code
$FName = $results->{FName};


Here is what I have so far: (including the HTML reply)

Code
#!/usr/bin/perl 

#use strict;
use DBI;

print "Content-type: text/html\n\n";

# Get the name and value for each form input:
@pairs = split(/&/, $ENV{'QUERY_STRING'});
# Then for each name/value pair....
foreach $pair (@pairs) {
# Separate the name and value:
($name, $value) = split(/=/, $pair);
# Convert + signs to spaces:
$value =~ tr/+/ /;
# Convert hex pairs (%HH) to ASCII characters:
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Store values in a hash called %FORM:
$FORM{$name} = $value;
}

$username = 'root';
$dsn = 'DBI:mysql:mysql';
$conn = DBI->connect('DBI:mysql:bcpadb;host=208.11.220.249', 'maxwell175', 'qwertyuiop', { RaiseError => 1 }) || die "Could not connect to the database";
$LName = $FORM{'LName'};
$FName = $FORM{'FName'};

TRYAGAIN:
$query = "SELECT * FROM People2 WHERE LName LIKE '$LName' AND FName LIKE '$FName'";
$query1 = $conn->prepare($query) || die "Error preparing query" . $conn->errstr;


$query1->execute || die "Error executing 'select' query: " . $query1->errstr;
#print "$query";

#try replaceing the while with this.
$results = $query1->fetchrow_hashref()

$FName = $results->{FName};
$LName = $results->{LName};
$AddrLine1 = $results->{AddrLine1};
$AddrLine2 = $results->{AddrLine2};
$City = $results->{City};
$Zip = $results->{Zip};
$WAddrLine1 = = $results->{WAddrLine1};
$WAddrLine2 = $results->{WAddrLine2};
$WCity = $results->{WCity};
$WZip = $results->{WZip};
$HPhone = $results->{HPhone};
$MPhone = $results->{MPhone};
$WPhone = $results->{WPhone};
$Email = $results->{Email};
#}


print <<HTMLPAGE;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv='X-UA-Compatible' content='IE=EmulateIE7' />
<title>BCPA page - MDTech</title>

<meta name="msvalidate.01" content="6698DB3266240D800A1DEFB2AEE5249D" />
<meta name="msvalidate.01" content="BA291C2BB06D4C099CF9138D94C4C24B" />
<meta name="google-site-verification" content="Mv8ukVrmYK4zMgdnRp4qYETNyRnPyRtaI-YEzYjDzV0" />
<meta name="msvalidate.01" content="BA291C2BB06D4C099CF9138D94C4C24B" />
<meta name="google-site-verification" content="Mv8ukVrmYK4zMgdnRp4qYETNyRnPyRtaI-YEzYjDzV0" />
<!--[if IE 7]>
<style>
p {
line-height:18px;
padding-bottom:0px;
}
h1 {
font-size:20px;
font-weight:bold;
color:#272e34;
padding-bottom:0px;
}
h2 {
font-size:14px;
font-weight:bold;
color:#272e34;
padding-bottom:0px;
}
</style>
<![endif]-->
<meta name="google-site-verification" content="Mv8ukVrmYK4zMgdnRp4qYETNyRnPyRtaI-YEzYjDzV0" />
<meta name="msvalidate.01" content="BA291C2BB06D4C099CF9138D94C4C24B" />
<meta name="google-translate-customization" content="4870ff0762da6435-906b3721014154a0-g256d826ced58f04d-9"></meta>

<link rel='stylesheet' type='text/css' href='http://cdn1.editmysite.com/editor/libraries/fancybox/fancybox.css?1348176505'></script>
<link rel='stylesheet' href='http://cdn1.editmysite.com/editor/images/common/common-v2.css?buildTime=1348176505' type='text/css' />
<link rel='stylesheet' type='text/css' href='files/main_style.css?1348197132' title='wsite-theme-css' />
<style type='text/css'>
#wsite-content div.paragraph, #wsite-content p, #wsite-content .product-block .product-title, #wsite-content .product-description, .blog-sidebar div.paragraph, .blog-sidebar p, .wsite-form-field label, .wsite-form-field label {}
#wsite-content h2, #wsite-content .product-long .product-title, #wsite-content .product-large .product-title, #wsite-content .product-small .product-title, .blog-sidebar h2 {}
#wsite-title{}
</style>
<script type='text/javascript'><!--
var STATIC_BASE = 'http://cdn1.editmysite.com/';
var STYLE_PREFIX = 'wsite';
//-->
</script>
<script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript' src='http://cdn1.editmysite.com/editor/libraries/jquery_effects.js?1348176505'></script>
<script type='text/javascript' src='http://cdn1.editmysite.com/editor/libraries/fancybox/fancybox.min.js?1348176505'></script>
<script type='text/javascript' src='http://cdn1.editmysite.com/editor/images/common/utilities-jq.js?1348176505'></script>
<script type='text/javascript' src='http://cdn1.editmysite.com/editor/libraries/flyout_menus_jq.js?1348176505'></script>
<script type='text/javascript'><!--
var IS_ARCHIVE=1;
(function(jQuery){
function initFlyouts(){initPublishedFlyoutMenus([{"id":"732580610550224581","title":"Home","url":"index.html"},{"id":"791199019507589116","title":"Software","url":"software.html"},{"id":"185665631450527889","title":"Contact Us","url":"contact-us.html"},{"id":"655691623107481862","title":"Register","url":"register.html"},{"id":"120377591448869403","title":"Windows 8 HOW-TOs","url":"windows-8-how-tos.html"},{"id":"383720836856858449","title":"HTTPS Mirror INFO","url":"https-mirror-info.html"},{"id":"970940401954682759","title":"How to install ooVoo","url":"how-to-install-oovoo.html"},{"id":"925835062994562531","title":"Subscribe for MDTech.us Newsletter","url":"subscribe-for-mdtechus-newsletter.html"},{"id":"664166098389600041","title":"MDT Certificate Authority","url":"mdt-certificate-authority.html"},{"id":"939902576679924408","title":"Visitor Map","url":"visitor-map.html"},{"id":"517608385647474105","title":"Install Teamviewer","url":"install-teamviewer.html"}],'590082422623526219',"<li class='wsite-nav-more'><a href='#'>more...<\/a><\/li>",'',false)}
if (jQuery) {
if (jQuery.browser.msie) window.onload = initFlyouts;
else jQuery(initFlyouts)
}else{
if (Prototype.Browser.IE) window.onload = initFlyouts;
else document.observe('dom:loaded', initFlyouts);
}
})(window._W && _W.jQuery)
//-->
</script>
</head>
<body class='wsite-theme-light wsite-page-bcpa-page'>
<div id="wrapper">
<div id="header">
<div id="sitename"><span id="wsite-title">MDTech</span></div>
</div>
<div id="navigation">
<div id="navigation"><ul><li id='pg732580610550224581'><a href='index.html'>Home</a></li><li id='pg791199019507589116'><a href='software.html'>Software</a></li></ul></div>
</div>
<div id="content-wrapper">
<div id="contents-body">
<div id="contents"><div id='wsite-content' class='wsite-not-footer'>
<h1>Edit your information and click &quot;Submit&quot;:</h1>
<form action="/BCPA/BCPA_form/PROC/done/" method="get">
First Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Last Name:<br />
<input type=text name="FName" value="$FName" style="height: 23px; width: 133px" readonly="readonly" />
<input type=text name="LName" value="$LName" style="height: 23px; width: 133px" readonly="readonly" /><br />
Email:
<br />
<input type="text" name="Email" value="$Email" style="height: 23px; width: 239px" />
<br /><br />
<h4>Your Address:</h4>
Address Line 1:<br />
<input type="text" name="AddrLine1" value="$AddrLine1" style="height: 23px; width: 239px" />
<br />Address Line 2:<br />
<input type="text" name="AddrLine2" value="$AddrLine2" style="height: 23px; width: 239px" />
<br />City:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Zip:<br />
<input type="text" name="City" value="$City" style="height: 23px; width: 125px" />&nbsp;&nbsp;&nbsp;
<input type="text" name="Zip" value="$Zip" style="height: 23px; width: 63px" /> (state not needed)
<br /><br /><br />
<h4>Work Info:</h4>
Company:<br />
<input type="text" name="Company" value="$Company" style="height: 23px; width: 125px" />
<br />
Job Title:<br />
<input type="text" name="Job_Title" value="$Job_Title" style="height: 23px; width: 156px" />
<br /><br />
<font size="2"><b>Work Address:</b></font><br /><br />
Address Line 1:<br />
<input type="text" name="AddrLine1" value="$WAddrLine1" style="height: 23px; width: 239px" />
<br />Address Line 2:<br />
<input type="text" name="AddrLine2" value="$WAddrLine2" style="height: 23px; width: 239px" />
<br />City:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Zip:<br />
<input type="text" name="City" value="$WCity" style="height: 23px; width: 125px" />&nbsp;&nbsp;&nbsp;
<input type="text" name="Zip" value="$WZip" style="height: 23px; width: 63px" /> (state not needed)
<br /><br />
<h4>Phone numbers:</h4>
Home Phone:<br /><input type="text" name="HPhone" value="$HPhone" style="height: 23px; width: 125px" /><br />
Mobile Phone:<br /><input type="text" name="MPhone" value="$MPhone" style="height: 23px; width: 125px" /><br />
Work Phone:<br /><input type="text" name="WPhone" value="$WPhone" style="height: 23px; width: 125px" /><br />
<br /><br />
<input type="button" action="submit" value="Submit" />
</form>
</div>
</div>
<div id="contents-bottom"></div>

</div>
</div>

<meta name="google-site-verification" content="Mv8ukVrmYK4zMgdnRp4qYETNyRnPyRtaI-YEzYjDzV0" />
<meta name="msvalidate.01" content="BA291C2BB06D4C099CF9138D94C4C24B" />

</body>
</html>
HTMLPAGE

exit;



(This post was edited by MDTech.us_MAN on Oct 1, 2012, 7:36 AM)


Edit Log:
Post edited by MDTech.us_MAN (Novice) on Oct 1, 2012, 7:36 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives