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

hmm MySQL not printing write

by Anonymous Monk
on Jul 19, 2002 at 14:32 UTC ( #183247=perlquestion: print w/replies, xml ) Need Help??
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

ok, it works now, butfor year its just putting the letter two in the d +atabase it suppost to be 02, and it prints 02 on the preview page @months = qw(January Febuary March April May June July August Septemb +er October November December); @hours = qw(1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 10 11 12); $time = ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = local +time(time); $year += 1900; $year = sprintf("%02d", $year % 100); $new = $lastnumber + 1; if($hour > 12) { $AP = "PM"; } else { $AP = "AM"; } print "<p>Your news has been added</p><u><b>Preview</b></u><br> <p>$months[$mon] $mday $year <b>at</b> @hours[$hour]:$min $AP +<b>($user)</b></p><p><b>",param("title"),"</b><br>",param("des"),"</p +>"; $sth = $dbh->prepare("INSERT INTO news(username, month, day, hour, mi +n, AP, title, description, year) VALUES ('$user', '$months[$mon]', '$ +mday', '$hours[$hour]', '$min', '$AP', ?, ?, '$year')"); $sth->execute(param("title"), param("des")) or die $dbh->errstr;
When it prints the year in the database it just prints 2, when its suppost to be 02, on the preview page it displays 02??

Replies are listed 'Best First'.
Re: hmm MySQL not printing write
by Cine (Friar) on Jul 19, 2002 at 14:52 UTC
    May I suggest that instead of using columns named month, day, hour and min you just have a single column called timestamp (which is updated automagically on writes thus saving all but the last two lines of code)

    T I M T O W T D I
Re: hmm MySQL not printing write
by katgirl (Hermit) on Jul 19, 2002 at 14:43 UTC
    In your database, is the data type for that column "number"? Cos if it is that will get rid of any leading zero's. Maybe you could change it to "text". (I don't know much about MySQL though - I know WHY it is, I just don't know the syntax, so don't shoot me :( ).
      I have it on int(5)
Re: hmm MySQL not printing write
by screamingeagle (Curate) on Jul 19, 2002 at 17:08 UTC
    int datatype columns will strip out the leading zeroes. if you want to display it with leading zeroes, then you could use the sprintf function to do so.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://183247]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2017-12-18 01:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (466 votes). Check out past polls.

    Notices?