Hi,
I have this cgi script which is a simple authentication web page, it check the value of the password_field and if correct call the subroutine alfa.
I don't know why it stops with an error when I click on "insert new stream"
I tried to call the subroutine without the authentication part and it works. -
#!/usr/bin/perl -Tw
-
use CGI;
-
$query = new CGI;
-
print $query->header;
-
print $query->start_html();
-
if (!$query->param) {
-
print $query->startform;
-
print $query->password_field(-name=>'the_password',
-
-size=>35,
-
-maxlength=>50);
-
print $query->br;
-
print $query->submit(-value=>'Submit your password');
-
print $query->endform;
-
} else {
-
$yourPassword = $query->param('the_password');
-
if ($yourPassword eq '123') { alfa ();} {print 'error';}
-
-
}
-
-
print $query->end_html;
-
-
-
-
sub alfa () {
-
use strict;
-
use CGI::Carp qw(fatalsToBrowser);
-
use CGI qw(:standard);
-
use DBI;
-
my $mode = param('mode');
-
my $url = url;
-
print header,
-
start_html;
-
-
print h2('insert values'),
-
start_form(),
-
textfield('DETAILS'), 'detail bor bla bla..' . br,
-
textfield('TARGET_DATABASE') . br ,
-
textfield('TARGET_HOST'). br,
-
textfield('TARGET_IP') . br,
-
textfield('TARGET_ACCOUNT') . br,
-
textfield('SOURCE_DATABASE') . br,
-
textfield('SOURCE_HOST'). br,
-
textfield('SOUCE_IP') . br,
-
textfield('SOURCE_ACCOUNT') . br,
-
textfield('STREAM_NAME') . br,
-
textfield('ID') . br,
-
submit('insert new stream'),
-
end_form;
-
-
if($mode eq 'process_form')
-
{
-
my $dbh = DBI->connect('DBI:Oracle:(DESCRIPTION = (ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = xx.xx.xx.xx)(PORT = xxxx)))(CONNECT_DATA =(SERVICE_
-
NAME = xxxxxxx)))', 'monitor', 'monitor', {RaiseError=>'1'});
-
my $sth = $dbh->prepare('insert into s_test (DETAILS, TARGET_DATABASE, TARGET_HOST, TARGET_IP, TARGET_ACCOUNT, SOURCE_DATABASE, SOURCE_HOST, SOUCE_IP, S
-
OURCE_ACCOUNT,STREAM_NAME, ID) values (? , ? , ?, ?, ?, ?, ?, ?, ?, ?, ?)');
-
$sth->execute(param('DETAILS'), param('TARGET_DATABASE'), param('TARGET_HOST'), param('TARGET_IP'), param('TARGET_ACCOUNT'), param('SOURCE_DATABASE
-
'), param('SOURCE_HOST'), param('SOUCE_IP'), param('SOURCE_ACCOUNT'),param('STREAM_NAME'), param('ID'));
-
$dbh->disconnect;
-
}
-
print end_html;
-
}
-
11 3374 numberwhun 3,509
Recognized Expert Moderator Specialist
In line 16, shown here: -
if ($yourPassword eq '123') { alfa ();} {print 'error';}
-
I took out the {print 'error';} and it gave a bunch of output. Try removing that and see if that is what you were looking for. Not sure why you had that print statement there, but it overrode the subroutine execution, or so it seems.
Also, any time you post code in the forums, please use code tags.
Regards,
Jeff
RonB 589
Recognized Expert Moderator Contributor
Here are some questions for you to think about. As you answer them, your problem and solution should be discovered.
Why are you loading the CGI module twice?
Why are you using CGI's OO interface in the begining but then switch over to the functional interface in the sub?
Why do you have the use statements in the sub and not at the beginning of the script?
Why are you specifying an empty prototype in the subroutine declaration? You should be receiving this warning:
main::alfa() called too early to check prototype at m4x123.pl line 16
Why are you enclosing the print 'error'; statement in it's own block?
Why are you outputting 2 sets of headers?
RonB 589
Recognized Expert Moderator Contributor
I have not tested the script but I don't think that print error statement prevented the script from working correctly.
After fixing the formatting of that else block, here is what it looks like. - else {
-
$yourPassword = $query->param('the_password');
-
-
if ($yourPassword eq '123') {
-
alfa();
-
}
-
-
{ print 'error'; }
-
}
It's more likely that it's the prototype that's causing the problem.
numberwhun 3,509
Recognized Expert Moderator Specialist
I agree with you that I don't see why that would have effected it, but when I removed the print statement it produced a totally different output.
RonB 589
Recognized Expert Moderator Contributor
I just tested the script as written by the OP and the only "error message" I receive is the one that is hard coded into the script and is displayed whenever the user clicks on the 'Submit your password' button.
The script works exactly as I would expect. Meaning that the form in the alfa() sub is displayed, but since there is no form field with the name of 'mode' anywhere in the script, then the corresponding DB code won't be executed.
Hi,
First of all thanks to all of you for the help.
I changed the code as follow(see m4x123.txt attached):
1) implemented the Rob's formatting at line 16-21
2) I've updated the script with form field with method=post, hidden name and value='process_ form'
I tested the subroutine again removing lines from 1 to 25 and using only "alfa ();" to call it and it works.
when I use all the script I can access the form for inserting the values in the form but after clicking on
the insert button I get the print 'error'; from line 23
from the error.log on the apache server:
[Tue Dec 29 11:46:39 2009] null: Use of uninitialized value in string eq at /u01/appl/ora102/product/http10g/Apache/Apache/cgi-bin/inspwd.pl line 19.
Still cannot figure out why the subroutine doesn't work if I call it from if statement.
should I use a different form ?
regards,
max
RonB 589
Recognized Expert Moderator Contributor
What makes you think the subroutine is not working? For me, it works exactly as I'd expect, but clearly it's not what you want. What are your expectations.
One of the first and most important steps in writing and troubleshooting code is the ability to clearly describe step by step what the code needs to do. This is called writing pseudo code. From there you fill in the code details to accomplish each step.
I have a good idea of what you want the script to do, but as written has a number of logic errors, which is why it's not doing what you want.
RonB 589
Recognized Expert Moderator Contributor
Line 31 is one logic error example.
How can you retrieve the value of a hidden form field before creating the form in which it is defined?
Hi Ron,
I just tried to reuse some code which I've found on internet since I like the flexibility and simplicity of perl/cgi but of course I'm not a perl expert
this for the insert into the database: http://www.expertwebinstalls.com/cgi...ipulation.html
and http://www.devdaily.com/perl/perl-cg...ield-html-form
for the authentication
btw I don't want necessarily use this code what I'm trying to do is just creating a simple form for inserting a row in my table after authentication through another form. If you could address me I would really appreciate it.
thanks,
Max
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Raju V.K |
last post by:
can I use javascript and PHP in the following manner to create a
pop-up window:
<--- in <head> </head>
<script language=javascript>
function popup(folder1, file1)
{
window1=open("solution.php?folder=folder1&file=file1");
}
|
by: Will Seay |
last post by:
At the end of this message I've pasted a script we're trying to modify
slightly. I don't believe it is VBscript or javascript but these are
the closest groups I could find with my limited programming knowledge.
Basically, we are trying to add a few lines to this script that will
execute a few shell commands (see comments at the very end of the
code). We think this may be ActionScript2 but aren't sure.
If you can offer any help, or know...
|
by: Eyal |
last post by:
Hey,
I would appriciate if anyone can help on this one:
I have a java object/inteface having a method with a boolean
parameter. As I'm trying to call this method from a javascript it
fails on a type mismatch.
It is positively because of the boolean(java primitive)parameter. It
goes fine if I change this parameter to int or String.
This inteface has a lot more methods which works fine, it is just the
|
by: CR1 |
last post by:
I found a great cookie script below, but don't know how to make it also pass the values sent to the cookie, to a querystring as well for tracking purposes. Can anyone help? If there was a way to simply pass the values in a cookie to the querystring that would be even easier, but from what I've been able to tell, cookie values can't be passed to a querystring.
I'm sure the answer will help alot of others who are using this script, and would...
|
by: Velislav |
last post by:
Hi,
I have a client script block, which is registered in my Page_Load.
However a button may result in the need to change the script which I've
registered.
Obviously the OnClick event occurs after Page_Load, so calling
RegisterClientScriptBlock with the same key does nothing.
| |
by: =?Utf-8?B?TG93bGFuZGVy?= |
last post by:
Hello,
I've built a web application that uses client script callbacks. It is used
on a large network with a large variety of user OSes and IE versions. It was
tested on IE 6 on different setups and IE 5.5 to a lesser degree without
problems.
I know of a least one user who gets an error in WebResource.axd when using
the application. The same error also occurs on a simple reproduction page
with just a button and a div. When the button...
|
by: Odd Bjørn Andersen |
last post by:
Is there a way to check the return status from a stored procedure when
called from a OS (Windows) script?
I have a stored procedure that does some checking in the database, and the
return status is set to 0 or -1 if 'OK' or 'not OK' respectively.
When I call the from CLP I get something like this:
Value of output parameters
--------------------------
|
by: ora2000 |
last post by:
Hi
I would like to create a unix script to connect to an ORACLE database using a oracle package. Also this script should provide functionality to call an oracle procedure that contains a parameter value that is passed to it. The parameter value passed to the procedure should be "editable" i.e user should be able to change it.
Please specify if any more information is needed
what I have done is the following
example script name ->...
|
by: peteinglastonbury |
last post by:
I'd be most grateful if someone would help me. I hope I'm in the right forum (apologies if not) - I'm not sure whether my problem is CGI or Javascript related.
I found a script called BatmoAudiopop.js which opens a pop-up browser window with an audio player when a link is clicked. Basically, it sets the right mime-type depending on the operating system and audio file type, then opens a window with the audio file (passed as a parameter) in...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |