Link to home
Create AccountLog in
Avatar of ellandrd
ellandrdFlag for Ireland

asked on

TOP MASTER/GURU/GENIUS QUESTION

looking for the Perl syntax of the PHP

<?php echo $_SERVER['PHP_SELF'];?>

very urgent!
ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Tintin
Tintin

or assuming you are using the CGI module (as you should be):

Obtaining the Script's URL

    $full_url      = $query->url();
    $full_url      = $query->url(-full=>1);  #alternative syntax
    $relative_url  = $query->url(-relative=>1);
    $absolute_url  = $query->url(-absolute=>1);
    $url_with_path = $query->url(-path_info=>1);
    $url_with_path_and_query = $query->url(-path_info=>1,-query=>1);

url() returns the script's URL in a variety of formats. Called without any arguments, it returns the full form of the URL, including host name and port number

http://your.host.com/path/to/script.cgi

You can modify this format with the following named arguments:

-absolute
    If true, produce an absolute URL, e.g.

/path/to/script.cgi
     

-relative
    Produce a relative URL. This is useful if you want to reinvoke your script with different parameters. For example:

    script.cgi

-full
    Produce the full URL, exactly as if called without any arguments. This overrides the -relative and -absolute arguments.

-path,-path_info
    Append the additional path information to the URL. This can be combined with -full, -absolute or -relative. -path_info is provided as a synonym.

-query (-query_string)
    Append the query string to the URL. This can be combined with -full, -absolute or -relative. -query_string is provided as a synonym.

Avatar of ellandrd

ASKER

ok so you might be able to help me with this question...

look here... if you fix my problems, its 1000 points as i have two questions open, 1 in perl for above and 1 in javascript for working with perl...


look here:

https://www.experts-exchange.com/questions/21333392/Require-Javascript-or-PERL-GURU-to-check-my-javascript-on-perl-page.html
or $ENV{SCRIPT_URI}, or (under Apache at least) $ENV{SCRIPT_NAME}. Now how is this a genius question?
sorry jmcg

what reason i ended up javing two questions open is, in the javascript thread, i asked fro help on the javascript side of things and from there Batalf who was helping me, said i need the perl syntax for PHP_SELF, which ended up me creating a new thread in the perl area.

then with getting a popst from perl experts, i though they might be able to help me solve my problem so i linked them to my javascript question.

so if tintin solved my javascript/perl problem by using what he posted here, i'd had to accept his answers on both thread, resulting him getting 1000 points from me...

sorry if i didtn explain it clear....

ellandrd
kandura

can you take a look at this and tell me why it isnt working?

#!/usr/bin/perl
use DBI;
use CGI ':standard';
my $jscript=<<EOF ;
bAllowSubmit = true;

function SubmitForm(obj, uid)
{
     if (bAllowSubmit == true)
     {
          bAllowSubmit = false;

          document.HiddenForm.elementName.value = obj.name;

          if (obj.checked == true)
          {
               document.HiddenForm.HiddenField.value = 1;    
          }
          else
          {
               document.HiddenForm.HiddenField.value = 0;          
          }
          document.HiddenForm.id.value = uid;
          document.HiddenForm.submit();
     }
}

EOF
print header,start_html(title=>'ODBC Test',script=>$jscript);
print << '_EOF_' ;
<form name="HiddenForm" action="$ENV{SCRIPT_URI}" method="post">
     <input type="hidden" id="elementName" name="elementName" value="">
     <input type="hidden" id="HiddenField" name="HiddenField" value="">
     <input type="hidden" id="UniqueID" name="id" value="">
</form>
_EOF_
$db = DBI->connect( "dbi:ODBC:PerlLink","","",{RaiseError => 1, printError => AutoCommit => 1})
or die "Unable to connect: " .$DBI::errstr . "\n";
if(param('id'))
{
     $query = $db->prepare("UPDATE tblData SET firstname='$firstname',lastname='$lastname',address='$address',age='$age',contactnumber='$contactnumber',confirmed='$confirmed') WHERE $record_id = param('id') ;") ;
     $query->execute($firstname,$lastname,$address,$age,$contactnumber,$confirmed,param('id')) ;
     $query->commit ;
}
$query = $db->prepare("SELECT * FROM tblData");
$query->execute;
$numrows = $query->rows;
print "<table border=1><tr><th>Record ID</th><th>Firstname</th><th>Lastname</th><th>Address</th><th>Age</th><th>Contact Num</th><th>Confirmed</th></tr>\n";
while (@array = $query->fetchrow_array)
{
       my ($record_id, $firstname, $lastname, $address, $age, $contact, $confirm) = @array;
       print "<tr><td>$record_id</td><td>$firstname</td><td>$lastname</td><td>$address</td><td>$age</td><td>$contact</td>" ;
       if($confirmed)
       {  
            ## make this condition suitable with data
            print "<form name=\"formcheckbox\"><td align=\"center\"><input type=\"checkbox\" name=\"job\" value=$record_id onClick=\"SubmitForm(this, $record_id);\" checked=1 ></td></form>" ;
       }
       else
       {
            print "<form name=\"formcheckbox\"><td align=\"center\"><input type=\"checkbox\" name=\"job\" value=$record_id onClick=\"SubmitForm(this, $record_id);\" checked=0 ></td></form>" ;
       }
}
print "</table>";
print end_html;
$db->disconnect;
exit(0);
right i have another idea?

instead of having the above page submit itself to update a db when a checkbox is ticked or untick, can somebody come up with a script that i can use in the action parameter of the form?

my idea is to have this display page in perl showing the data from the fields in the ms access db. so now if a user ticks/unticks checkbox, run another perl script in the action parameter of the form to update the db and redirect bk to this page...

e.g
user unticks checkbox, when they untick it submit the form.

action="SOME_SCRIPT_TO_UPDATE_DB.pl"...

this SOME_SCRIPT_TO_UPDATE_DB.pl updates db and redirects bk to parent page displayQueryReport.pl

first of all, do you think this will work?

if so, feel free to change around the above perl script page.

The way I see it, there are two paths to your script: one where the user simply requests to see the data, and one where he modifies that data (and is presented with the new information).
You could easily do this in one script. Just make a clear separation between the actions it has to perform:

1. display screen
2. update database

It would help if you put those two things in separate subroutines. A skeleton could be this:

      #!/usr/bin/perl
      use DBI;
      use CGI ':standard';
      use strict;
      use warnings;

      ### main execution loop
      if(param('id')) {
            update_record();      
      }

      display_data();


The "update_record" sub would *only* update the database with the supplied data.
The "display_data" would be responsible for presenting the screen with the rows of the database.


If you use the CGI functions for html generation, then any forms will become self-referential automatically.
Something like this:

    print start_form(),
        hidden(-name => 'elementName'),
        hidden(-name => 'HiddenField'),
        hidden(-name => 'id'),
      end_form();
   

By the way, I think the way you update the database has some room for improvement. In fact, it looks to me like your SQL has syntax errors.
Here's how I would write that bit:

      sub update_record {
             $query = $db->prepare(q{
                   UPDATE tblData SET
                        firstname     = ?,
                        lastname      = ?,
                        address       = ?,
                        age           = ?,
                        contactnumber = ?,
                        confirmed     = ?
                   WHERE
                        record_id     = ? ;
             });
             $query->execute($firstname,$lastname,$address,$age,$contactnumber,$confirmed,param('id')) ; ### where do you get those variables from?
      }

Now there's no possibility for SQL injection, and your query becomes more readable.
if i opened another 500 point question would your code it for me. as i was telling manav etc, i only know the skin and bones of perl and thats what i was asking so many questions...

if so would you recode the above code in my 03/02/2005 10:06AM GMT post?