NodeReaper has asked for the wisdom of the Perl Monks concerning the following question:

Replies are listed 'Best First'.
Re: MySQL Problem
by RMGir (Prior) on Jul 19, 2002 at 13:17 UTC
    Log into mysql from the command line, "use" the database the news table is in, and type "describe news;".

    That will tell you what the key fields are for the news database. You have a key that's required to be unique, and you're trying to put in '0' for it, which is already there.

    As an alternative, check the variables you're substituting into the query; one of them is probably 0.

    It's possible you're trying to shove non-numeric data into a numeric field; I'm guessing mysql would interpret that as 0, but I'm not sure.
    --
    Mike

Re: MySQL Problem
by erasei (Pilgrim) on Jul 19, 2002 at 13:18 UTC
    This is not a Perl problem, as said in your title. Therefore, perlmonks is probably not the best place to be asking it. Since you know you have a MySQL problem, try looking through the docs on MySQL.com. They have a great search engine and you can find anything you ever wanted to know. You need to be looking for things about 'Primary Keys' and 'Unique Indexes' to solve your problem.
      ok, it works now, butfor year its just putting the letter two in the database 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;