Jump to content

mySql - DupcliateEntries


mikey3521

Recommended Posts

Hello right now i'm working on a script where i'll allow a user to post a link to a database table. How would I go abouts coding the following, heres what I want to-do.

 

Lets say someone submitted the link  joeblow.com to $submitlink

 

-connect to the mysql-

select `linkaddy` from `links`

then

if `linkaddy` != $submit

then insert...

else

echo "sorry, link already added";

 

Hope i'm clear with that, now i'm pretty sure we'll have to load the mysql into an array? then run a loop to check the submitted link against each row? i just don't know how.Any help would be awesome, thanks

Link to comment
https://forums.phpfreaks.com/topic/56401-mysql-dupcliateentries/
Share on other sites

No, you're right. You dont need to put it into an array. Try something like:

 

<?php
$postedlink = $_POST['yourfield'];
$sql = mysql_query("SELECT COUNT(*) FROM `links` WHERE `linkaddy`='$postedlink'");
$num = mysql_result($sql,0,'COUNT(*)');
if($num ==1){
//already entered
}else{
//not entered, so insert into the database
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.