low tech
12-06-2010, 08:47 AM
Hi all
anybody any idea why this code doesn't return the expected data?
I get this:
These are your list of duplicates:
Duplicate Txn ID: 0
Duplicate Email Addresses: 0
Duplicate Txn ID: e
Duplicate Email Addresses: e
BUT I expect smthg like this
These are your list of duplicates:
Duplicate Txn ID: 12345678
Duplicate Email Addresses: someemail@abc.com
Duplicate Txn ID: 12345678
Duplicate Email Addresses: someemail@abc.com
$checkquery = "SELECT txn_id, user_email FROM users WHERE txn_id='".mysql_real_escape_string($txn_id)."' OR user_email='".mysql_real_escape_string($user_email)."'";
// file_put_contents('debug.txt', $checkquery);
$result = mysql_query($checkquery, $Connect) or die("Duplicate txn id check query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
$num_rows= mysql_num_rows($result);
if($num_rows !=0){
$duplicates=mysql_fetch_assoc($result);
$content="These are your list of duplicates:\n\n\n";
foreach($duplicates as $duplicate){
$content .= "Duplicate Txn ID: " . $duplicate['txn_id'] . "\n\n";
$content .= "Duplicate Email Addresses: " . $duplicate['user_email'] . "\n\n";
}
mail($notify_email,"Duplicates Found",$content);
}
LT
MattF
12-06-2010, 08:49 AM
http://uk3.php.net/manual/en/function.mysql-fetch-assoc.php
low tech
12-06-2010, 09:29 AM
Hi Matt F
OK finally
I got something --- after trial and a million errors
LT
MattF
12-06-2010, 11:44 AM
This part of your code:
$num_rows= mysql_num_rows($result);
if($num_rows !=0){
$duplicates=mysql_fetch_assoc($result);
$content="These are your list of duplicates:\n\n\n";
foreach($duplicates as $duplicate){
$content .= "Duplicate Txn ID: " . $duplicate['txn_id'] . "\n\n";
$content .= "Duplicate Email Addresses: " . $duplicate['user_email'] . "\n\n";
}
should now be looking something like this then?
if (mysql_num_rows($result))
{
$content = 'This is your list of duplicates:'."\n\n\n";
while ($duplicate = mysql_fetch_assoc($result))
{
$content .= 'Duplicate Txn ID: '.$duplicate['txn_id']."\n\n";
$content .= 'Duplicate Email Address: '.$duplicate['user_email']."\n\n";
}
low tech
12-06-2010, 12:56 PM
Hi MattF
Not exactly --- but nearly I guess
If I send (for test) one duplicate tnx_id and one duplicate user_email
I get in my error mail --- each one ---- so I thought it's good.
BUT IF I send just one duplicate eg txn_id
I get that txn_id in my error email PLUS the user email that belongs to that row BUT is not a duplicate email (it just belongs to that row)--- not good hahahahhaha
So I made progress after three days --- but i'm not there:-(
and I can't see a way to JUST get only the duplicate(s) that I send and nothing else.
if ($checkquery = "SELECT txn_id, user_email FROM users WHERE txn_id='".mysql_real_escape_string($txn_id)."' OR user_email='".mysql_real_escape_string($user_email)."'" ){
// file_put_contents('debug.txt', $checkquery);
$result = mysql_query($checkquery, $Connect) or die("Duplicate txn id check query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
while ($row = mysql_fetch_assoc($result)){
//echo $row["txn_id"];
//echo $row["user_email"];
$content = "Duplicate Txn ID: " . $row["txn_id"] . "\n\n";
$content .= "Duplicate Email Addresses: " . $row["user_email"] . "\n\n";
}
mail($notify_email,"Duplicates Found",$content);
}
LT
syncupsolutions
12-06-2010, 01:25 PM
Hi MattF
Not exactly --- but nearly I guess
If I send (for test) one duplicate tnx_id and one duplicate user_email
I get in my error mail --- each one ---- so I thought it's good.
BUT IF I send just one duplicate eg txn_id
I get that txn_id in my error email PLUS the user email that belongs to that row BUT is not a duplicate email (it just belongs to that row)--- not good hahahahhaha
So I made progress after three days --- but i'm not there:-(
and I can't see a way to JUST get only the duplicate(s) that I send and nothing else.
if ($checkquery = "SELECT txn_id, user_email FROM users WHERE txn_id='".mysql_real_escape_string($txn_id)."' OR user_email='".mysql_real_escape_string($user_email)."'" ){
// file_put_contents('debug.txt', $checkquery);
$result = mysql_query($checkquery, $Connect) or die("Duplicate txn id check query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
while ($row = mysql_fetch_assoc($result)){
//echo $row["txn_id"];
//echo $row["user_email"];
$content = "Duplicate Txn ID: " . $row["txn_id"] . "\n\n";
$content .= "Duplicate Email Addresses: " . $row["user_email"] . "\n\n";
}
mail($notify_email,"Duplicates Found",$content);
}
LT
Does the txn_id not auto-increment ?
If your looking for duplicates with both email address and txn_id the same, then you need to change the OR in your query to AND.
Something like:
if ($checkquery = "SELECT txn_id, user_email FROM users WHERE txn_id='".mysql_real_escape_string($txn_id)."' AND user_email='".mysql_real_escape_string($user_email)."'" ){
// file_put_contents('debug.txt', $checkquery);
$result = mysql_query($checkquery, $Connect) or die("Duplicate txn id check query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
while ($row = mysql_fetch_assoc($result)){
//echo $row["txn_id"];
//echo $row["user_email"];
$content = "Duplicate Txn ID: " . $row["txn_id"] . "\n\n";
$content .= "Duplicate Email Addresses: " . $row["user_email"] . "\n\n";
}
mail($notify_email,"Duplicates Found",$content);
}
MattF
12-06-2010, 01:28 PM
Compare the output against your original vars. id and e-mail within if blocks.
if ($row["user_email"] == $user_email)
Same for the id.
low tech
12-06-2010, 01:37 PM
Hi MattF
yes I like yr idea for comparison ---- I wasn't sure how to do that but now I can have a go.
I did change OR to AND before but I got nothing in my error email hhahaah so I changed it back. But i'll play with that now too and see what happens.
Also i'm not expecting duplicates --- BUT if it did happen then it will either be a duplicate txn_id or user_email or very very very unlikely BOTH hahhhaa
All i'm thinking to do is IF it did arise and there was duplicate(s) -- I want to catch it and send error to myself.
So my meaniing is it's possible tp be ONE or THE OTHER or BOTH :-)
anyway
really appreciate yr help
thank you
LT
back to the drawing board hahaha
low tech
12-06-2010, 02:10 PM
Hi again MattF
well here is my latest attempt
no it doesn't work hahahhaha line 104
syntax error, unexpected '}'
while ($row = mysql_fetch_assoc($result)){
//echo $row["txn_id"];
//echo $row["user_email"];
if ($row["txn_id"] == $txn_id){
$content = "Duplicate Txn ID: " . $row["txn_id"] . "\n\n"
}else{$content = "Duplicate Txn ID:none "}; //LINE 104
if ($row["user_email"] == $user_email){
$content .= "Duplicate Email Addresses: " . $row["user_email"] . "\n\n"
}else{$content .= "Duplicate Email:none "};
}
mail($notify_email,"Duplicates Found",$content);
}
LT
Does the txn_id not auto-increment?
No Sir.
low tech
12-06-2010, 03:01 PM
Hi MattF
ok my last effort --- late now
this one finds the txn_id but not the user_email when both duplicates are sent
so I guess it passes and has done enough once its found txn_id --- in other words --- crap code hahaahhaha
while ($row = mysql_fetch_assoc($result)){
//echo $row["txn_id"];
//echo $row["user_email"];
if ($row["txn_id"] == $txn_id)
$content = "Duplicate Txn ID: " . $row["txn_id"] . "\n\n";
if ($row["user_email"] == $user_email)
$content .= "Duplicate Email Addresses: " . $row["user_email"] . "\n\n";
}
mail($notify_email,"Duplicates Found",$content);
}
LT
MattF
12-06-2010, 05:30 PM
You're overwriting your $content var whenever you match the id.
$content = "Duplicate Txn ID: " . $row["txn_id"] . "\n\n";
You need the .= rather than just =.
low tech
12-06-2010, 11:35 PM
Hi MattF
Thank you very much for yr help.
Can I ask you --- post #9 -- I did this
if ($row["txn_id"] == $txn_id){
$content = "Duplicate Txn ID: " . $row["txn_id"] . "\n\n"
}else{$content = "Duplicate Txn ID:none "};
BUT the braces {} seemed to be wrong
are they wrong/not needed within a WHILE loop?
I mean I don't have them in my last attempt and the code worked.
LT