Jump to content

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
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.