Jump to content

Stop from inserting duplicate fields


Zoofu

Recommended Posts

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

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
}

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.