|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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... |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > Doing more than one thing....... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|