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.


In reply to if statement problem using mysql by CreationP

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.