MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 25th, 2000, 02:49 PM
mp3findit mp3findit is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2000
Location: Quispamsis, NB, Canada
Posts: 49 mp3findit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
Send a message via ICQ to mp3findit
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

Reply With Quote
  #2  
Old October 26th, 2000, 07:17 AM
Kyuzo Kyuzo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 1999
Location: Annapolis, Maryland US
Posts: 113 Kyuzo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 9
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...


Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Doing more than one thing.......


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway