mikey3521 Posted June 20, 2007 Share Posted June 20, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/56401-mysql-dupcliateentries/ Share on other sites More sharing options...
GingerRobot Posted June 20, 2007 Share Posted June 20, 2007 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56401-mysql-dupcliateentries/#findComment-278547 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.