SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2000
    0 Post(s)
    0 Thread(s)
    Question 1: HOw can I avoid adding duplicate entries. I was reading something about a unique constraint but found out that mySQL does not support that. I already have another column as my primary key. If I make the "Business Name" the primary key, will this avoid duplicate entries with the same business name? How can I add or change the primary key on existing columns?

    Question 2: I am trying to insert the expiration date when the business listing is submitted from my PHP3 pages. I was trying the current date function + an INTERVAL. But nothing was being inserted into my mySQL database column....

    This is what I was inserting into my PHP 3 page:
    "Expiration_Date=CURDATE(), INTERVAL 6 MONTH)";

    I also tried many variations, and nothing worked...I know you can do this for Select queries, but can you use this method for INSERT?

  2. #2
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Melbourne, Australia
    2 Post(s)
    0 Thread(s)
    HOw can I avoid adding duplicate entries.
    Try setting a UNIQUE key on the column where you'd like to avoid duplicates. For example:

    mysql> CREATE UNIQUE INDEX index_name
             --> ON tbl_name (col_name);
    For more information on this SQL command, see Section 7.32 of the MySQL Reference Manual.

    I am trying to insert the expiration date ...
    Your code looks slightly broken. Try this:

    "Expiration_Date=ADDDATE(CURDATE(), INTERVAL 6 MONTH)";
    Kevin Yank
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts