Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

if statement problem using mysql

by CreationP (Initiate)
on May 31, 2012 at 14:55 UTC ( #973540=perlquestion: print w/ replies, xml ) Need Help??
CreationP has asked for the wisdom of the Perl Monks concerning the following question:

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.

Comment on if statement problem using mysql
Download Code
Re: if statement problem using mysql
by toolic (Chancellor) on May 31, 2012 at 15:04 UTC
Re: if statement problem using mysql
by Eliya (Vicar) on May 31, 2012 at 15:05 UTC
    while (@option - $sth1 ->fetchrow_array()){ ^

    Is this a typo?

      Dear Eliya, No it wasn't a typo. I don't know why but I thought it was the correct form. I changed the '-' to '=' and worked as intended. Thank you very much for scanning my code and finding out the error. You guys here in perlmonks are lifesavers!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://973540]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2014-12-28 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (182 votes), past polls