#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Quispamsis, NB, Canada
    Posts
    49
    Rep Power
    14
    I have a script that adds fields to a database, but if a URL is added twice i would like it to tell them it is already there. I was thinking of doing a:
    SELECT * FROM table WHERE url = '$url'
    and if it cant find it then it adds it and if it can find it it informs the person....but i cant quite get it right. Can someone help? I use php (just so you know)

    thanks,
    Scott
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    Annapolis, Maryland US
    Posts
    113
    Rep Power
    15
    Consider making the URL field a primary key in the table so duplicates may not be added. If it cannot be made the primary key, then make it a unique key and include the appropriate error checks/error messages in your PHP script when inserting new data in the DB table.

    > alter table table_name add UNIQUE url_ind (URL);

    <?
    $query="insert into table_name values('$a', '$b', '$c', '$URL'...etc.";

    $result=mysql_query($query, $mysql_link);

    if($result){ print"Info added.";}

    else
    {
    $errno=mysql_errno($mysql_link);
    $error=mysql_error($mysql_link);
    print"ERROR: $errno - $error";
    }
    ?>

    Something like that...

Similar Threads

  1. Replies: 3
    Last Post: February 13th, 2004, 02:12 PM
  2. Some thing to help
    By paparika in forum Beginner Programming
    Replies: 2
    Last Post: January 29th, 2004, 03:57 PM
  3. onClick thing..
    By banan2 in forum HTML Programming
    Replies: 4
    Last Post: December 1st, 2003, 04:35 PM
  4. Click counter thing
    By banan2 in forum PHP Development
    Replies: 6
    Last Post: November 13th, 2003, 02:05 PM

IMN logo majestic logo threadwatch logo seochat tools logo