I'm using a table named 'options' which has 1 field with the name 'log' and one record which can be only 1 or 0. Default value is 1. I want to enable or disable logging to my progra, using the following code:
if ($choise ==6){
$sql1 = "select * from scanner.options";
$sth1 = $dbh ->prepare($sql1);
$sth1->execute or die "SQL Error: $DBI::errstr\n";
while (@option - $sth1 ->fetchrow_array()){
$log = $option[0];
}
if ($log == 1){
print "Logs = 1";
print "\n\nWould you like to disable logging? (press 1 for yes
+ or anything else for no): ";
my $o_log= <STDIN>;
if ($o_log == 1){
my $sql = "UPDATE options SET log=0 WHERE log=1";
$sth = $dbh->prepare($sql);
$sth->execute
or die "SQL Error: $DBI::errstr\n";
}
}
else{
print "Logs = 0";
print "\n\nWould you like to enable logging? (Press 1 for yes
+or anything else for no): ";
my $o_log= <STDIN>;
if ($o_log == 1){
my $sql = "UPDATE options SET log=1 WHERE log=0";
$sth = $dbh->prepare($sql);
$sth->execute
or die "SQL Error: $DBI::errstr\n";
}
}
}
Using this code I cannot get the program to go into the first if function ($log == 1). I also tried with if ($option[0] == 1) and it still does not work. My value in the mysql table is 1. Why is it not working and how can I make it work? Thank your for your time.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|