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.