Zoofu Posted September 21, 2009 Share Posted September 21, 2009 Only if the fields `uid` and `path`... If they're the same as something already on there, how do I stop it from inserting? <?php $id = $_GET['id']; $queryl=mysql_query("SELECT * FROM `users` WHERE `id`=".$_SESSION['uid']."") OR die(mysql_error()); $fetcha_array = mysql_fetch_array($queryl); $usernameb = $fetcha_array['username']; $idb = $fetcha_array['id']; $tokensb = $fetcha_array['tokens']; $postsb = $fetcha_array['posts']; $blurbb = $fetcha_array['blurb']; $commentsb = $fetcha_array['comment']; $avatarb = $fetcha_array['avatar']; $usernameb = $fetcha_array['username']; $realnameb = $fetcha_array['name']; $statusb = $fetcha_array['status']; $queryc = mysql_query("SELECT * FROM users WHERE id = '$id'"); $fetch_array = mysql_fetch_array($queryc); $username = $fetch_array['username']; $id = $fetch_array['id']; $tokens = $fetch_array['tokens']; $posts = $fetch_array['posts']; $blurb = $fetch_array['blurb']; $comments = $fetch_array['comment']; $avatar = $fetch_array['avatar']; $realname = $fetch_array['name']; $status = $fetch_array['status']; $sql4 = "INSERT INTO `friends` (`uid`,`path`,`username`,`name`,`avatar`) VALUES ('.$id.','$idb','$usernameb','$realnameb','$avatarb')"; $sql5 = "INSERT INTO `friends` (`uid`,`path`,`username`,`name`,`avatar`) VALUES ('.$idb.','$id','$username','$realname','$avatar')"; $res4 = mysql_query($sql4) or die(mysql_error()); $res5 = mysql_query($sql5) or die(mysql_error()); ?> <html> <head> <title>My-Buzz | Add user</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> </body> </html> <?php header("location: index.php"); ?> Link to comment https://forums.phpfreaks.com/topic/175035-stop-from-inserting-duplicate-fields/ Share on other sites More sharing options...
mikesta707 Posted September 21, 2009 Share Posted September 21, 2009 you could make both those columns unique in your table. Or you can do a query to check, and if no rows are returned (IE no duplicates) than do the query. if not, don't. Link to comment https://forums.phpfreaks.com/topic/175035-stop-from-inserting-duplicate-fields/#findComment-922479 Share on other sites More sharing options...
Alex Posted September 21, 2009 Share Posted September 21, 2009 Ideally, yes, you would make them unique fields. You could however also do something like this: $check = mysql_query("SELECT uid, path FROM `users` WHERE uid='$uid' OR path='$path'"); if(!mysql_num_rows($check)) { //Doesn't exist, insert } Link to comment https://forums.phpfreaks.com/topic/175035-stop-from-inserting-duplicate-fields/#findComment-922482 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.