Jump to content

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
}

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.