Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Duplicate SQL Entries


I have a buddy system on my site and I have found that duplicate buddies can be added into the database. Here how I have this set up:

user 1 want to add user 2 as a buddy.
user 1 goes to user 2's page and clicks "add as buddy"
A PM goes to user 2 and asks him if he accepts or declines
if user 2 clicks accept a php script is run

Problem:
This script need to detect if that buddy already exists, if so do nothing or overwrite the original. Right now it just adds the entry again. I am using a very simple table:

UID   BID
---------
1   |   2

This would mean user id 1 has a buddy with a buddy id 2

Here is the non-functional code:

$query = mysql_query("UPDATE buddies SET uid='$uid', bid='$bid' WHERE uid='$uid' && bid='$bid'");
print "Buddy Has been overwritten";
//would prefer it not do anything at all if entry exists
if ($query == 0)
{
// No records updated, so add it
$query = mysql_query("INSERT INTO buddies (uid, bid) VALUES ('$uid', '$bid')");
print "Buddy Added";}




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Duplicate Entries
I am currently using the form below for people to enter data into mysql, at the moment this has no methed of checking to see if the data they enter already exists, can anyone provide help as to how to this? PHP Code:

Selecting Duplicate Entries
I'm having the following problem: Let's assume I have a table with 3 fields: ID (type int), NAME(type varchar), EMAIL (type varchar) in a mysql db. The fields have the following data stored:

1, jack, jack@jack.com
2, tom, jack@jack.com
3, jack, jack@jack.com
.
2000, jack, jack@jack.com

Now let's say I have like some thousand entries like that one above with each one containing different data. So if there are entries which have the same email adress, how I can I select exclusively those entries with the duplicate data in it? So the result of a selection should look something like this: (If I want to show the selection results in html): PHP Code:

Ignoring Duplicate Entries
I have this samll piece of code that gets the last 5 post from a forum and presents them on the home page. But i am not sure how to prevent duplicate entries from appearing on it. PHP Code:

Preventing Duplicate Form Entries
I have an HTML generated php form which when submitted enters the contents into an SQL database. The problem is that once the user enters their information and the page returns to tell them their submission was successful, if they hit reload/refresh a second submission is entered and this could go on forever unless I include some kind of code which prevents this. I have thought about using the refresh meta tag but really want to exercise my options before I do that.

Don't Display Duplicate Database Entries?
I have a restaurants database that has a lot of restaurants listed with the same name in the same city with only the category changed. This is the code that I have that displays the list of restaurants. Can someone tell me what to add to it so that it will only display one of each restaurant of a certain name? PHP Code:

Remove Duplicate Entries From TXT File ?
Is it possible to use PHP to open/read a TXT file (i.e. IP.TXT) that
contains ip addresses (1 per line), remove any duplicates found, and
re-write the file back out to IP_NEW.TXT ?

The reason is, I have ips coming from several sources, i.e. URLSCAN logs,
MySQL dbs, etc. and I can use a DISTINCT on the individual queries, but I
then combine all the results into 1 file which may contain duplicates.

Returning Field Results But No Duplicate Entries
I have a large MySql database full of addresses of clients.

I am trying to use php to retrieve and display a list of all the countries that my clients exist in. Which I can do:

--------
$sql = "SELECT * from Sheet1" ;
$qry=mysql_query($sql);
while ($result= mysql_fetch_array($qry))
{
echo "".$result[11]."<br>";
}
--------
However you can see the problem is this returns EVERY clients country so I end up with a list of duplicate countries.

I would like to display the list of countries but not repeat any countries in the list.

Deleting Duplicate Entries From MySQL Database Table
The topic is related to MySQL database.

Suppose a table "address" contains the following records

-------------------------------------------------------
| name | address | phone |
-------------------------------------------------------
| mr x | 8th lane | 124364 |
| mr x | 6th lane | 435783 |
| mrs x | 6th lane | 435783 |
| mr x | 8th lane | 124364 |
-------------------------------------------------------

Quote:

Duplicate Entries - From "There Must Be An Easy Solution!!??? (by Mcsimon)"
Duplicate entries are not too harmful in the sites I have made. Usually the output is sorted (order by ...) and duplicate entries become apparent.

However, I was thinking of warning users about 'duplicate' entries if they happen together. This would high-light the "BACK BUTTON - RE-ENTER" scenario.

- store the mysql last_insert_id() in the user's table.
- when an insert is processed, compare the new input fields to the last_insert_id row.

Other people may be working on "Life and Death" situations. Could their concern lead
to SELECTing using one or two "sort of unique" fields and, if any hits, SELECTing using all input fields? If a complete match occurs, they could do something.

ON DUPLICATE KEY
I have a query where I'm trying to insert data using the ON DUPLICATE KEY syntax.

When I run the script, I receive the following message:
FS30YF100FS30YF100Unknown column 'a' in 'field list'. PHP Code:

Prevent Duplicate
I have this code that inserts the email address into a database but I want to check the database to see if that email address already exists and if so tell the user. I've looked all over to find out how to do this. PHP Code:

Duplicate Enterys
What is the best way to stop duiplicate enterys on to a data base from a website, for instance if the user presses refresh, or presses back and then submits again.

up to yet i have been using a check in the database for the same info being added, and using an if statment..

Duplicate Data
i am doing a simple program to let user entry their travelling claim. how can i notify user when there are duplicate data (they enter same data twice) ?

Duplicate Entry
this functions adds new locations in am_ups_shipment_location table after a tag in XML is detected it is pointed towards this function and this function then goes and adds the new location.

for the first time when i run the php prgoram the new location gets added.but when i refresh ,again the same location gets added but with different id[id is on autoincrement].

here is how my table looks after refresh.[you can see duplicate entry].This is what i dont wnat...i dont want a duplicate entry.
Can you please help me get rid of this duplicate entry by writing some update functions and checking against already present data in the table? Code:

Duplicate Results
I'm fairly new to PHP and after some trial and error managed to get the rsults I want from the following script, except that now some of the results are being duplicated. Code:

Checking For Duplicate Users
Can anyone point me in the right direction? I'm looking for help in checking my user table for existing names and passwords before i add a new user.

Insert On Duplicate Key Update
I have the following code: PHP Code:

Trying To Duplicate Form Fields.
What I would like is to when someone writes in one field. The same text is written in a seperate field. But without sending anything. all internally. Anyone have a clue?

Duplicate Emails From Formmail.php
Can anyone tell me why I might be getting 2 email returns for every form post using formmail.php?

Both are identical, both have the same time sent.

I'm using the recipient in the formmail.php script because when I use recipient in my form, it doesn't work.

Print Non Duplicate Records
I want to search a table and display the records which are not duplicated in a different field of the same table. For instance I can print the duplicate records with this piece of code:

While Producing Duplicate Results
I'm trying to add the ability to attach categories and subcategories attributes to each post. I've created two tables (chap_category, and chap_sub_category) that stores the names and a unique id number for each.

It's suppose to list the Categories that corresponds to the forum I'm adding a new post to. Under each of the Categories, its corresponding Sub-categories will be listed. But now it's listing the proper sub categories for the first category, for the second category it lists the first category's sub categories, for the third category it lists the first's sub-categories AND the second's subcategories...etc. PHP Code:

Duplicate Elements In Array
is there an efficient way to check if all the entries in an array are unique or if there are duplicates?

Exact Duplicate Rows
I find many different exact duplicate rows in the table. I would like to remove all the duplicates and keep just one copy of each. Can I do this with mysql or PHP?

Remove Partial Duplicate
I need to create a PHP/MySQL solution for the following problem. I have a database with a single coulmn and around 100 unique rows. Each column is 8 groups of alphanumeric data seperated by a space. (i.e. 10 2213 24841 37123 6c d2 e1 b4)

Each row must be unique and if a new row is added and the first 4 groups match an existing row, I need to delete both rows. So if I try to add 10 2213 24841 37123 7c d3 a1 w4 it would not add the new row and delete the existing row because 10 2213 24841 37123.

If the first 4 groups don't match any existing row, it should be added. If there is an exact match the nothing should be added and nothing deleted. I am sure this sounds strange, but I could use some help finding the soultion.

DBG For PHP Client (duplicate Name Problem)
Having just compiled DBG 2.15.1 and trying to use it with PHP (cli)
give some some problem.

Verions:
DBG 2.15.1
PHP 4.4.4 (cli)

It works fine compiled with the Apache module but when I try to use it with
the client I get the following warnings trying to run the client version of
PHP.

PHP Warning: Function registration failed - duplicate name - debugbreak in
Unknown on line 0
PHP Warning: Function registration failed - duplicate name -
outputdebugstring in Unknown on line 0
PHP Warning: Function registration failed - duplicate name -
dbg_get_profiler_results in Unknown on line 0
PHP Warning: Function registration failed - duplicate name -
dbg_get_all_module_names in Unknown on line 0
PHP Warning: Function registration failed - duplicate name -

....

and so on

This problem can usually be seen if you try to load a module that has
already been compiled in but in this case "dbg.so" is definitely not
compiled into the PHP version.

Have anyone seen this before or have any ideas on where to start debgugging
this problem? (I'd rather not re-invent the wheel if someone already found
the solution)

Ignoring Duplicate SQL Results?
I'm making a site where people can upload effect pedal settings for songs. So I have a list of pedals, lets say I have 2 in the list, wah 1 and wah 2. I'm trying to count how many songs use each pedal. Problem is, there could be 2 different settings for the same pedal (dependng on how fast you want to play it, etc).

So if we have 2 songs, song 1 and song 2, and they each have 2 settings, my num_rows query will return 4. However, I only want it to return 2 since I'm counting songs, not individual effects. Is there any way to do this?

SELECT * FROM effects WHERE song='$song_id' AND pedal='$pedal_id'
Is the query I have now.

How To Duplicate A Text String?
What code do I use to duplicate a text string? For example I have:
$activ = md5( $activ );The thing is, I want to take $activ and convert into md5 hash and store it AND store it in the original format. As of now, all I have it is that it is converting into md5 hash and storing it that way.

Avoiding Duplicate Results??
Does anyone know if this is possible:

I'm running a query against a db and am pulling name and ticket # (for a helpdesk)...  What I'd like to do is take the results from the "Name" field, but only show EACH NAME ONCE in a table.  For example, I might get 200 results back, but only want to show the name of the person once, with how many tickets they have assigned to them.

So it would look like this:

___Name___|___Number of tickets___
___Bob____|__________3__________
___John____|_________23__________
___Mark____|_________4___________

...etc, etc...  does anyone know how to go about starting this?  I'm assuming an array of sorts. 

Duplicate Entry '127' For Key 1
when i first hit the index.php page it says "Duplicate entry '127' for key 1" if i refresh it goes away, then it randomly shows up on pages but goes away for awhile after i refresh them. where do i look to fix this?

Remove Duplicate Words
I have some chunks of text where I need to remove duplicate words. e.g. "one one, two three, two" should be "one, two three,)".

I could do that using arrays etc, but it's quite slow doing that way because of the size of the text. Is it possible to achieve the same result using regular expressions and preg_replace?

Implode Produces Duplicate Results
I'm using implode to concantenate an array and I'm getting two of everything. Ahhh. Documentation says this should work.

while ($myrow = mysql_fetch_array($result)) {

$FieldArray= implode(" ",$myrow);

printf("<p><a href="EditMasterContent.php?RecordID=%s">%s</a>
", $myrow[0], $FieldArray);

}

Could someone PLEASE tell me why it's duplicating every field content? I'm sure there's a simple explanation . .

How To Prevent Duplicate Posts In My Guestbook?
I have a little form that people can post their messages, but there has been a lot of duplicate entries by people pressing the submit button twice or by hitting refresh. How do I prevent multiple posts of the same entry?

How To Prevent Duplicate Login With Session
When username and password is correct. I register username is session. but the problem is I already login in my computer and can login again in another computer. How to prevent duplicate login?

__autoload And Duplicate Vars Clash
I am rewriting an application to take advantage of the __autoload
functionality. If I accidentally declare a variable in the parent class
which was previously declared in a child class, the child class fails on
load, the script terminates, and no error is given.

Is there anything I can do to show this error and its source?...

Duplicate Variable Names In The URL Need To Be Put Into An Array
I have a url with duplicate variable names and I need them to be dumped into an array.

For example if I have http://www.google.com?boo=0&boo=1&boo=2
I want to have an array that is
boo[0] = 0, boo[1] = 1, boo[2] = 2

How do I do this?

I know $_SERVER['argv'] will grab everything after the '?' in the URL, but I don't know what do from there.

Handling Duplicate Array Elements
$var['item']['quantity'] = 10;

How would I subtract values from a nested array?

Also, if I have duplicates like these..

$var['item'] = 'foo'
$var['item']['quantity'] = 5;
$var['item'] = 'foo'
$var['item']['quantity'] = 11;

How can I sort them out so it looks like this:

$var['item'] = 'foo'
$var['item']['quantity'] = 16;

I tried something like..

function sortCart() {
if (isset($_SESSION['scart'])) {
$cart = $_SESSION['scart'];
return $cart;
} else {
$cart = $_SESSION['cart'];
$dupes = array_count_values($cart);
$keys = array_keys($dupes);
$arr = array();
$counter = count($dupes);
for($i = 0; $i < $counter; $i++) {
$arr[] = array('item' => $keys[$i], 'quantity' => $dupes[$i + 1]);
}
return $arr;
}

array_count_values doesn't work in nested arrays.. but it helps sort out duplicates.. any ideas?

Removing Duplicate Rows In Using ODBC
I am transferring an access database on a client side to a sql database on server. The problem that i am facing is during this transfer some of the rows are getting duplicated and I want to avoid them . I saw a procedure somewhere which made a distinct copy of the table to another table and then rename that. could you please tell me what is the error in the following code and why is it not working.It is giving the error as:

"The database engine could not lock table 'query2' because it is already in use by another person or process., SQL state S1000 in SQLExecute in c:webmonitortoserver.php on line 45" Code:

Duplicate Records In DB When Importing From CSV File
The code below is used to grab each row from a CSV file (except the
first row) and insert it into a database, as long as it's not already
in the DB.

If I echo each row's data, it appears only once on the page. But, for
some reason it inserts each row into the database 3 times. The code
that echos the data, and the DB insertion code all appear within the
same for loop.

The database insertion code (below) works perfectly in another script.
It's just copied/pasted into the for loop.

$row = 0;
$handle = fopen ("some-file.csv","r");
while ($data = fgetcsv ($handle, 1000, ",")) {
if($row == 0){
// set the varible array
$num = count ($data);
$csvNames = array();
for ($c=0; $c < $num; $c++) {
$csvNames[$c] = $data[$c];
eval("$" . $data[$c] . " = array();");
}
$row = 1;
}else{
$num = count ($data);
$row++;
for ($c=0; $c < $num; $c++) {
$buildEval = "$" . $csvNames[$c] . " = "" . $data[$c] .
"";";
eval($buildEval);
echo $buildEval . "<br>"; // this properly displays only one
row's data from the CSV file, then displays the next row in the CSV
file when it loops again.

// BUT FOR SOME REASON, THE DB CODE BELOW INSERTS EACH ROW FROM THE
CSV FILE 3 TIMES.

// Set variables with current date and time to be inserted into DB
later
$appDate = date('Y-m-d');
$appTime = date('H:i:s');

// Prepare the phone numbers for easy input into the database further
down this page.
$fHomePhoneCombined = $fHomePhone1 . "-" . $fHomePhone2 . "-" .
$fHomePhone3;
$fBusinessPhoneCombined = $fBusinessPhone1 . "-" . $fBusinessPhone2 .
"-" . $fBusinessPhone3;

// Connect to the database
$db = mysql_connect ("localhost", "username", "password");
mysql_select_db ("mydatabase");

// Check to see if the record is new,
$newRecord = 1;
$queryNewRecord = mysql_query("SELECT * FROM cust_test WHERE
first_name = '$fFirstName' AND last_name = '$fLastName' AND email =
'$fEmail'");
if (mysql_num_rows($queryNewRecord) > 0){
$newRecord = 0;
}

// If it's NOT a new record, insert the contents into cust_test_bad DB
// I'll insert this code later. It's not important for this test.

// Write the information to the customers table, if it's a new record.

if ($newRecord == 1){
$query = "INSERT INTO cust_test SET
application_date = '$appDate',
application_time = '$appTime',
first_name = '$fFirstName',
last_name = '$fLastName',
email = '$fEmail',
address = '$fAddress',
state = '$fState',
zip = '$fZip',
home_phone = '$fHomePhoneCombined',
best_time_to_call = '$fBestTime',
lead_buyer = '$lbuy'";


$result = mysql_query($query) or die('Failed because:
'.mysql_error());
}

} // end of for ($c=0; $c < $num; $c++)
}
}
fclose ($handle);

Duplicate Input In 2 Form Fields
Hope to check the input in two form fields:

input in "emailto" form field: a@a.com
input in "emailfrom" form field: a@a.com, b@b.com, c@c.com

I hope to remove the duplicated input "b@b.com" in "emailfrom" form output and then keep only the remaining part of the string. How can I do that? I have though a way in combining the two fields input as an array and then use "array_unique" to check the duplicate. And then, to separate the two fields input again.

Avoiding Duplicate Array Elements
Im having a problem with this code. Im
trying to remove duplicate elements from an array created via $_GET.
I want users to be able to click on a link which sends an email
address to an array. I just want to remove duplicate email addresses
from the array. Ive tried array_unique() on my test server but it
doesnt work. So i tried to remove duplicates myself before storing
them into the array. The script works great without the checking,

session_start();

$email = $HTTP_GET_VARS['email'];
if (isset($_SESSION['Array']))
{

$Array = $_SESSION['Array'];
$numElements = count($Array);
for($counter=0; $counter < $numElements; $counter++)
{
/* Problem is here */if ($Array[$counter] == $email)
{
exit();
}

else
{
array_push($_SESSION['Array'],$email);
$EmailArray = $_SESSION['Array'];
$_SESSION['Array'] = $EmailArray;
}
}
}

else
{
$EmailArray = array();
array_push($EmailArray,$email);
$_SESSION['Array'] = $EmailArray;
}

Occasionally Get Duplicate Emails From Mail()
I'm trying to spam myself :- with 2,000 emails, shooting for 15,000,
and I will occasionally get two identical emails. I'm putting a
$counter++ as the from and part of the subject line so I can see
what's going on. Any reason why this might happen? here's my code just
in case.....

Getting Data For Duplicate Keys In $_POST
I'm trying to process a form that I got from a JSP generated page.
Basically, want to take out and process some of the data, and redirect the
rest to a JSP page that will handle the rest. All works well, i traverse
$_POST, writeout hidden input fields and autosubmit the form with a little
javascript, a perfectly acceptable solution for our users.

However, the data the JSP page sends contains one certain input with the
same name a couple of times. Due to complicated reasons, I cannot change
that name into a PHP-style array. PHP, however, throws all the values of
those fields away except for the last one.

Is there any way to retreive data from inputs with duplicate names? I know
that with GET, I could just parse the query string myself, but sadly i need
to use $_POST (the thing I'm processing in PHP is a file upload). I have no
way of changing the input names themselves (and see no alternative other
than pulling a lot of ugly javascript hacks in the JSP page to fake it all).

Check Duplicate Record In Mysql
I am trying to make sure that I do not insert a duplicate record in the database.  Here is my code:

Sql - Query To Remove Duplicate Rows?
I have a database with 20,000 records - the fields are ip, datetime, pageurl

Is there a way to do a mysql query where it will return the all results where I specify the pageurl but doesn't include duplicates of the ip field?

Prevent Adding Duplicate Records
theres a XML file located on the internet. every week or so. this xml file gets updated with one or two new  entry's.

i have a php script which can read all the entrys i want from this xml file. and then put it into a database.

the problem is say i run the php script again to update the database and add the new entry's that the xml file has. every thing gets added again. each time the script is run. the enter xml file entry's are added again.
so the database get full with duplicates triplcate records ect ect.

how would i go about preventing the same record being added over and over.

Limit The Entries
How can I limit the number of entries into the database, so after the limit is reached a text like "sorry limit is reached" is displayed, if the limit is not reached a form is displayed.

Approval Of Entries
I'm designing my first PHP and MYSQL application. It is going to be a database of singing groups. I'm going to allow individuals to enter thier groups info into the database. However, I'd like to be able to set up an admin screen that would allow me to approve each entry first before it can be viewed. As well as let me do some other admin functions, such as edit records, delete records. Any suggestions?

File Entries
I want to open a local file and add lines of text to the top of it, before any previous text in the file. How?

Add Entries To Array
What I want to achieve:
A select list in a form should grow with every data entry.
Example:

I have a list of towns to choose from for a single entry.
If there is a town, not in the list, I would like to have the option to enter one in a text field.

Next time I approch the input form, the newly entered town shows up in the select list.

What do I have to do, to expand the select list (resp. the table behind)?


Copyright © 2005-08 www.BigResource.com, All rights reserved