codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  invalid syntax  catalyst at 16:30 on Thursday, January 19, 2006
 

I have created a form and run a perl script

But when I submit the form I get an invalid syntax error displayed in the browser

here is my code

"#!/usr/bin/perl


##############################################################
## PNet.pl - a script to send formatted GoldMine Web Import
## data.
##
## Written by JCS
##
## Please make sure that you have set up Perl for use on your
## web machine before attempting to use this script.
##
## Disclaimer: Although we've tried to make this script as
## straightforward as possible, you will probably
## have to make changes to it to get it to work.
## FrontRange makes no claims as to the
## guarantees that this code will function.
##
##############################################################


print "Content-type: text/html\n\n";
$Body = "";
$XML = "";
$strDecodeTemp = "";
$smtp_server = "192.168.0.77";
$reply_from_name = "Web Import";
$sendto = "chris.hurcombe\@catalyst-commercial.co.uk"; ## (REMEMBER THE \ BEFORE THE @ SIGN)##
$versionnumber = "Version 1.0";

if($ENV{'REQUEST_METHOD'} eq "GET") {
&nopost;
}else{
&get_form_data;
&main;
}

sub HTMLEncode
{
$strDecodeTemp =~ s|\&|\&amp\;|g;
$strDecodeTemp =~ s|<|\&lt\;|g;
$strDecodeTemp =~ s|>|\&gt\;|g;
$strDecodeTemp =~ s|\"|\&quot\;|g;
return $strDecodeTemp;
}
sub get_form_data
{

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$buffer);
foreach $pair (@pairs)
{
@a = split(/=/,$pair);
$name=$a[0];
$value=$a[1];
$name =~ s/\+/ /g;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ s/~!/ ~!/g;
$value =~ s/\+/ /g;
$value =~ s/(\r)+/\-\-/g;
$value =~ s/\n+//g;
$value =~ s/(\-\-)+/\n/g;
$value =~ s|\&|\&amp\;|g;
$value =~ s|<|\&lt\;|g;
$value =~ s|>|\&gt\;|g;
$value =~ s|\n|<br>\n|g;

push (@formdata,$name);
push (@formdata,$value);
push (@form,$nameform);
push (@form,$valueform);
push (@formname,$name);
push (@formvalue,$value);


}
%formname=@formname;
%formname;
%formvalue=@formvalue;
%formvalue;
%formdata=@formdata;
%formdata;


}

sub Decode
{
$intX = 0;
$intY = 0;
$intMod =0;
$intTemp = 0;
$intY = 0;
$strValueOut="";
$intL = length($strDecodeTemp);
for ($intX=1; $intX<=($intL/4); $intX++)
{
$Modulus = $intX % 2;
$strTemp="";
$strMod="";
if ($Modulus == 0)
{
$strMod = substr(substr($strDecodeTemp,$intY,4),0,2);
$strTemp = substr(substr($strDecodeTemp,$intY,4),length(substr($strDecodeTemp,$intY,4))-(2));
}
else
{

$strMod = substr(substr($strDecodeTemp,$intY,4),length(substr($strDecodeTemp,$intY,4))-(2));
$strTemp = substr(substr($strDecodeTemp,$intY,4),0,2);
}

$intMod=hex($strMod);
$intTemp=hex($strTemp);
$intTemp=$intTemp-$intMod;
$strValueOut=$strValueOut.chr($intTemp);
$intY= $intY + 4;
}
return $strValueOut;

}


sub main
{

$strDecodeTemp = $formdata{'SMTP'};
$smtp_server = &Decode;
$strDecodeTemp = $formdata{'SendToEmail'};
$sendto=&Decode;
$strDecodeTemp= $formdata{'OnNewSendGMEmail'};
$OnNewSendGMEmail =&Decode;

$strDecodeTemp= $formdata{'OnDUPSendGMEmail'};
$OnDUPSendGMEmail =&Decode;

$strDecodeTemp= $formdata{'OnNewAttachTrack'};
$OnNewAttachTrack =&Decode;

$strDecodeTemp= $formdata{'OnDupAttachTrack'};
$OnDupAttachTrack =&Decode;

$strDecodeTemp= $formdata{'Word'};
$Password =&Decode;

$strDecodeTemp= $formdata{'DupLogic'};
$DupLogic =&Decode;

$OutputAs = $formdata{'OutPutAs'};
$DuplicateCount=0;
$XML = "<gmdata>";
if ($formdata{'DuplicateCount'}ne '')
{
$DuplicateCount =$formdata{'DuplicateCount'};
}

if ($DuplicateCount >0 || $OnNewSendGMEmail ne '' || $OnDUPSendGMEmail ne '' ||
$OnNewAttachTrack ne '' || $OnDupAttachTrack ne '')
{
$Body = $Body."[Instructions]\n";
$XML = $XML."<Instructions>";
if ($DuplicateCount > 0)
{
$RealCount=0;
for ($indexval = 0; $indexval < @formvalue; $indexval++)
{
${'myname'} = $formname[$indexval];
$myname = $formname[$indexval];
${'myvalue'} = $formvalue[$indexval];

if(length($myname)> 17)
{
$name = substr($myname,0,17);
if ($name eq "DuplicateChecking")
{
$RealCount = $RealCount + 1;
$Body = $Body."DupCheck".$RealCount."=".$myvalue."\n";
$strDecodeTemp = $myvalue;
$myvalue = HTMLEncode;
if ($myvalue eq "EMAIL")
{
$XML = $XML."<DupCheck>EA1</DupCheck>";
}
elsif ($myvalue eq "WEBSITE")
{
$XML = $XML."<DupCheck>WS1</DupCheck>";
}
else
{
$XML = $XML."<DupCheck>".$myvalue."</DupCheck>";
}
}
}
}
if($DupLogic ne '')
{
$Body = $Body."DupLogic=OR\n";
}

}

if ($OnNewSendGMEmail ne '')
{
$Body = $Body."OnNewSendGMEmail=".$OnNewSendGMEmail."\n";
$strDecodeTemp = $OnNewSendGMEmail;
$OnNewSendGMEmail = HTMLEncode;
$XML = $XML."<OnNewSendGMEmail>".$OnNewSendGMEmail."</OnNewSendGMEmail>";

}
if ($OnDUPSendGMEmail ne '')
{
$Body = $Body."OnDUPSendGMEmail=".$OnDUPSendGMEmail."\n";
$strDecodeTemp = $OnDUPSendGMEmail;
$OnDUPSendGMEmail = HTMLEncode;
$XML = $XML."<OnDupSendGMEmail>".$OnDUPSendGMEmail."</OnDupSendGMEmail>";

}
if ($OnNewAttachTrack ne '')
{
$comma =index($OnNewAttachTrack, ",",0);
$Body = $Body."OnNewAttachTrack=".$OnNewAttachTrack."\n";
if ($comma eq -1)
{
$strDecodeTemp = $OnNewAttachTrack;
$OnNewAttachTrack = HTMLEncode;
$XML = $XML."<OnNewAttachTrack>".$OnNewAttachTrack."</OnNewAttachTrack>";
}
else
{
($track, $user) = split(/,/, $OnNewAttachTrack);
$strDecodeTemp = $track;
$track = HTMLEncode;
$strDecodeTemp = $user;
$user = HTMLEncode;
$XML = $XML."<OnNewAttachTrack User=".chr(34).$user.chr(34).">".$track."</OnNewAttachTrack>";
}
}
if ($OnDupAttachTrack ne '')
{
$comma =index($OnDupAttachTrack, ",", 0);
$Body = $Body."OnDupAttachTrack=".$OnDupAttachTrack."\n";
if ($comma eq -1)
{
$strDecodeTemp = $OnDupAttachTrack;
$OnDupAttachTrack = HTMLEncode;
$XML = $XML."<OnDupAttachTrack>".$OnDupAttachTrack."</OnDupAttachTrack>";
}
else
{
($track, $user) = split(/,/, $OnDupAttachTrack);
$strDecodeTemp = $track;
$track = HTMLEncode;
$strDecodeTemp = $user;
$user = HTMLEncode;
$XML = $XML."<OnDupAttachTrack User=".chr(34).$user.chr(34).">".$track."</OnDupAttachTrack>";
}


}
if ($Password ne '')
{
$Body = $Body."Password=".$Password."\n";
$strDecodeTemp = $Password;
$Password = HTMLEncode;
$XML = $XML."<Password>".$Password."</Password>";

}

if($DupLogic ne '')
{
$XML = $XML."<DupLogic>OR</DupLogic>";
}
else
{
$XML = $XML."<DupLogic>AND</DupLogic>";
}



$XML = $XML."</Instructions>";
}
$Body = $Body."[Data]\n";
$XML = $XML."<accounts><account>";

$Phone = "";
$EA = "";
$WS = "";
$PR = "";




for ($indexval = 0; $indexval < @formvalue; $indexval++)
{
${'myname'} = $formname[$indexval];
$myname = $formname[$indexval];
${'myvalue'} = $formvalue[$indexval];


if ($myname ne "GMsubmit" && $myname ne "SMTP" && $myname ne "OnNewSendGMEmail" &&
$myname ne "OnDUPSendGMEmail" && $myname ne "OnNewAttachTrack" &&
$myname ne "OnDupAttachTrack" && $myname ne "SendToEmail" && $myname ne "DuplicateCount" && $myname ne "Word" &&
$myname ne "OutPutAs" && (substr($myname, 0, 17) ne "DuplicateChecking" && $myname ne "DupLogic" && substr($myname, 0, 7) ne "pretty_" ))
{

if($myvalue ne '')
{

$Body = $Body.$myname."=".$myvalue."\n";
$strDecodeTemp = $myvalue;
$myvalue = HTMLEncode;

if ((substr($myname,0,5) ne "PHONE") && ($myname ne "FAX") && ($myname ne "EMAIL") && ($myname ne "WEBSITE"))

{

$PR = $PR."<property name=".chr(34).$myname.chr(34)." db_name=".chr(34).$myname.chr(34).">";
$PR = $PR."<property_string>".$myvalue."</property_string>";
$PR = $PR."</property>";
}
else
{
if(substr($myname,0,5) eq "PHONE")
{
$Phone = $Phone."<phone international=".chr(34)."0".chr(34)." type=".chr(34).$myname.chr(34)." source_fld=".chr(34).$myname.chr(34).">";
$Phone = $Phone."<properties><property name=".chr(34)."phone_number".chr(34)."><property_string>".$myvalue."</property_string></property></properties>";
$Phone = $Phone."</phone>";
}
elsif (substr($myname,0,3) eq "FAX")
{
$Phone = $Phone."<phone international=".chr(34)."0".chr(34)." type=".chr(34).$myname.chr(34)." source_fld=".chr(34).$myname.chr(34).">";
$Phone = $Phone."<properties><property name=".chr(34)."phone_number".chr(34)."><property_string>".$myvalue."</property_string></property></properties>";
$Phone = $Phone."</phone>";
}
elsif (substr($myname,0,7) eq "WEBSITE")
{
$WS = $WS."<website primary=".chr(34)."1".chr(34)." id=".chr(34)."WS1".chr(34).">";
$WS = $WS."<properties><property name=".chr(34)."web_site".chr(34)."><property_string>".$myvalue."</property_string></property></properties>";
$WS = $WS."</website>";
}
elsif (substr($myname,0,5) eq "EMAIL")
{
$EA = $EA."<email primary=".chr(34)."1".chr(34)." id=".chr(34)."EA1".chr(34).">";
$EA = $EA."<properties><property name=".chr(34)."email_address".chr(34)."><property_string>".$myvalue."</property_string></property></properties>";
$EA = $EA."</email>";
}
}
}
}
}

if ($PR ne '')
{
$XML = $XML."<properties>".$PR."</properties>";
}
if($Phone ne '')
{
$XML = $XML."<phone_numbers>".$Phone."</phone_numbers>";
}
if($EA ne '')
{
$XML = $XML."<emails>".$EA."</emails>";
}
if($WS ne '')
{
$XML = $XML."<websites>".$WS."</websites>";
}
$XML = $XML."</account></accounts></gmdata>";

print("<!--\n\n".$XML."\n\n".$Body."\n\n-->");

$msgSubject = "Web Import";
$msgMessage = "";
if ($OutputAs eq "INI")
{
$msgMessage = $Body;
}
else
{
$msgMessage = $XML;
}

eval { require(Net::SMTP)};
if ($@)
{
print "Net::SMTP Failed to load. Please make sure that you have the NET:SMTP module from <a href=\"http://www.cpan.org/modules/index.html\" target=\"_new\">CPAN</a>.";
exit;
}

$smtp = Net::SMTP->new($smtp_server);
$smtp->mail("no-reply@frontrange.com");
$smtp->to ($sendto);
$smtp->data();
$smtp->datasend("To: ".$sendto."\n");
$smtp->datasend("From: GoldMine WebImport<no-reply\@frontrange.com>\n");
$smtp->datasend("Subject: $msgSubject\n");
$smtp->datasend("Content-Type: text/x-gm-impdata");
$smtp->datasend("\n\n");
$smtp->datasend($msgMessage."\n");
$smtp->datasend("\n");
$smtp->datasend("\n");
$smtp->datasend("\n");
$smtp->datasend("\n");
$smtp->dataend(); # Finish sending the mail #
$smtp->quit; # Close the SMTP connection #

&success;


}


sub nopost
{


print <<"MYMAINtext";

<html>

<head>
<title>D'oh!</title>
</head><body bgcolor="#cfcfcf">
<center>


<table width=500 border=1><tr><td bgcolor="#000080">
<br><br>
<font face="Arial" color="#ffffff">
<center>Error occured. Must be POST instead of GET.
</center></font>
<br><br>
</td></tr></table>
</center>

</body></html>

MYMAINtext

exit;

}

sub success
{



print <<"Myformatsuccess";

<html>
<head>
<title>Thank You.</title>
</head>
<body>
<BR><BR><CENTER>
<h2>Your form has been submitted successfully!</h2>


</CENTER>



</body>
</html>

Myformatsuccess


exit;

}
"

  Re: invalid syntax  mimir at 12:37 on Monday, February 26, 2007
 

Run small peaces of that code at a time and see if its doing what its supposed to do.









CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  How to send multiple perameters in SOAP request.
•  Java code for Insert picture on the table in spreadsheet
•  Re: Problem with concatenation
•  how to genrates the crystal report by sending a id at runtime
•  help me
•  pls help me with this..
•  Re: Security - Code verify
•  Job @ EarlySail
•  Job @ EarlySail (perl)


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007