List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:August 12 1999 3:08am
Subject:Re: help with TIMESTAMP
View as plain text  
At 7:57 PM -0700 8/11/99, Z Mehta wrote:
> I am working with a form and want a timestamp value added to the
>table every time the form is submitted.  This seems like a easy task
>but the now() function returns an error.
>
>$Qno = now();
>$query = "INSERT INTO submission VALUES($Qno, NULL, NULL, NULL, NULL,
>'$Type','$subject','$Industry','$Details', '$Special', 'StartDate',
>'$Year',
>'$Website', '$Articles', '$Summarize', '$PayArticles', '$Newsgroups',
>'$Browser')";
>$result = mysql_query($query);


NOW() is a MySQL function, not a PHP function.  You don't need to
call NOW(), anyway.  Since the Qno column is a TIMESTAMP, just insert
a NULL into it and MySQL will set the column to the current date and
time.

If you really want to call NOW, write your statement like this:

INSERT INTO submission VALUES(NOW(), ...



In addition, there is a second problem that you didn't ask about:


>And I set my table up like this:
>
>Create table submission (Qno  timestamp(10) primary key NOT NULL,
>Account int, Company varchar(30), ....


You can't really make Qno a primary key because you have no guarantee
that the values will be unique.  If you insert two records during
the same second, the timestamp values would be identical, and the
second insert will fail.

-- 
Paul DuBois, paul@stripped
Thread
help with TIMESTAMPZ Mehta12 Aug
  • Re: help with TIMESTAMPPaul DuBois12 Aug