I'm able to write to the DB when i use a static value, when i use the $_GET method it enumerates the webform values to the URL, but then not to the DB. i have tried to debug using values like print $_GET; but nothing is displayed, i can't work out why it will pick up the values, but won't parse them to the DB. $_POST is the same, when you use print $_POST['value'] is prints ''
PLEASE HELP- thanks in advance
CODE:
#!/usr/bin/perl --
# Create the necessary headers
print "Content-type: text/html\n\n";
# Use the DBI module
use DBI;
use CGI::Carp qw/fatalsToBrowser/;
# Declare local variables
my ($databaseName, $databaseUser, $databasePw, $dbh);
my ($stmt, $sth, @newRow);
$Phone = $_REQUEST["Phone"];
$Email = $_REQUEST["Email"];
$Enquiry = $_REQUEST["Enquiry"];
$FistName = $_REQUEST["FirstName"];
$Address1 = $_REQUEST["Address1"];
$Address2 = $_REQUEST["Address2"];
$Suburb = $_REQUEST["Suburb"];
$State = $_REQUEST["State"];
$Postcode = $_REQUEST["Postcode"];
$Authorised = $_REQUEST["Authorised"];
# Connect to the database
# Note this connection can be used to
# execute more than one statement
# on any number of tables in the database
$dbh = DBI->connect("DBI:mysql:database=complete_Enquiry;host=localhost", "complete_DB", 'passwordremoved') ¦¦
die "Connect failed: $DBI::errstr\n";
print $Phone
# Create the statement.
#$stmt = "INSERT INTO Client #(Phone,Email,Enquiry,FirstName,Surname,Address1,Address2,Suburb,State,Postcode,Authorised)
#VALUES('$_GET[Phone]','$_GET[Email]','$_GET[Enquiry]','$_GET[FirstName]','$_GET[Surname]',
#'$GET_[Address1]','$_GET[Address2]','$_GET[Suburb]','$_GET[State]','$_GET[Postcode]','$_GET[Authorised]')";
#) VALUES ('"$_POST['FirstName']"', '". $_POST['Surname']."', '".$_POST['Phone']."','". $_POST['email'] #."','".$_POST['Address1']."','".$_POST['Address2']."','".$_POST['Suburb']."','".$_POST['State']."','".$_POST['Postcode']."',
#'".$_POST['Enquiry']."','".$_POST['Authorised']."');
#$_POST['FirstName'],$_POST['Surname'],$_POST['Phone'],$_POST['Email'],
#$_POST['Address1'],$_POST['Address2'],$_POST['Suburb'],$_POST['State'],$_POST['Postcode'],
#$_POST['Enquiry'],$_POST['Authorised'])";
# Prepare and execute the SQL query
#$sth = $dbh->prepare($stmt) ¦¦ die "prepare: $stmt: $DBI::errstr";
#$sth->execute ¦¦ die "execute: $stmt: $DBI::errstr";
#print "complete";
# Clean up the record set and the database connection
#$sth->finish();
#$dbh->disconnect();
[edited by: phranque at 6:36 am (utc) on Sep. 23, 2009]
[edit reason] fixed sidescroll [/edit]
from the perlop man page [perldoc.perl.org]:
Single quotes indicate the text is to be treated literally with no interpolation of its content.
hard to tell which commented code was causing which problem but this may be part of it.
the major issue you are having is that you are trying to use php methods in perl.
unless you have added something you haven't shown, the _POST, _GET & _REQUEST arrays are not native perl nor supported by the CGI module as far as i know.
try this:
FETCHING THE VALUE OR VALUES OF A SINGLE NAMED PARAMETER [perldoc.perl.org]
the $query->param version of my script is below, i'm only using the print command to enumerate the variables, before i put the DB push module in.
#!/usr/bin/perl --
# Create the necessary headers
print "Content-type: text/html\n\n";
use CGI;
$query=new CGI;
select(STDOUT); $¦=1; # make unbuffered
require 5;
# Declare local variables
#variables for database parse DO NOT DELETE
#my ($databaseName, $databaseUser, $databasePw, $dbh);
#my ($stmt, $sth, @newRow);
$Phone = $query->param("Phone");
$Email= $query->param("Email")
$Enquiry= $query->param("Enquiry")
$FirstName = $query->param("CompanyName");
$Surname = $query->param("Address1");
$address1 = $query->param("Address2");
$address2 = $query->param("Address3");
$Suburb = $query->param("Suburb");
$State = $query->param("State");
$Postcode= $query->param("Postcode")
@names = $query->param($Phone);
print $Phone;
CGI::Carp qw/fatalsToBrowser/; doesn't use the cgi module, when i put in use CGI;
i get: Can't call method "param" on an undefined value at webform.cgi line 19.
line 16 is commented out, i've put the non functioning code seperately so no one gets confused :P
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
$query=new CGI('');
# Declare local variables
#variables for database parse DO NOT DELETE
#my ($databaseName, $databaseUser, $databasePw, $dbh);
#my ($stmt, $sth, @newRow);
my @parameters = $cgi->param; #gets the names of all form fields
my %params = $cgi->Vars; #stores all form fields as name/value pairs in a hash
$Phone = $query->param("Phone");
$Email= $query->param("Email");
$Enquiry= $query->param("Enquiry");
$FirstName = $query->param("CompanyName");
$Surname = $query->param("Address1");
$address1 = $query->param("Address2");
$address2 = $query->param("Address3");
$Suburb = $query->param("Suburb");
$State = $query->param("State");
$Postcode= $query->param("Postcode");
Print $Phone;
I used to know this stuff, this is soooo frustrating- that'll teach my to go from coding to Infrastructure consulting... lol
the cpanel error log only has
[Thu Sep 24 07:09:11 2009] [error] [client 124.168.158.234] Premature end of script headers: /home/complete/public_html/cgi-bin/webform.cgi
[Thu Sep 24 07:08:17 2009] [error] [client 124.168.158.234] Premature end of script headers: /home/complete/public_html/cgi-bin/webform.cgi
I **have heard** that the FTP clients should manage this on upload but have never seen it work. I use HomeSite in which I can set up to save files as Unix files.
If I save a file in PC format to send to someone I know will open in Windows Notepad, then forget to change it back and edit a perl script, it will 500.every.single.time.
There should be/are some freebie text editors out there that can save in Unix format, one less thing to worry about.
Testing and debugging offline is critical. Download and install Perl on your local system, you can then open a command prompt, navigate to the directory, and type perl yourscript.cgi. This will eliminate direct errors in the script.