...

View Full Version : How do I get the 'result' of this query into my error notify mail??



low tech
12-03-2010, 03:37 AM
Hello everyone

How do I get the 'result' of this query into my error notify mail??

It will either fail on one or both --- (or none) --- but if fail how do I get the reesult into my error report to myself??

I tried puuting $result in but that just gives me Resource id #3

and this gives me the query $checkquery.



$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());
if (!mysql_fetch_array($result)) { do smthg}


else{
// DUPLICATE: error notify
mail($notify_email, "VERIFIED DUPLICATED TRANSACTION or EMAIL"); }


LT:confused:

Fumigator
12-03-2010, 05:44 AM
In your mind, what is a "fail"? Do you mean the query returns nothing? Or there's a duplicate txn_id?

The function mysql_fetch_array() returns an array of column values if a row is found, and FALSE if a row is not found. So if it returns FALSE, that means there is no data fetched so you can't display any fetched data.

$result stores what PHP calls a query resource. There's no data from the query stored in $result; that's why you call mysql_fetch_array().

low tech
12-03-2010, 06:20 AM
Hi Fumigator

not sure if what i'm thinking to do is technically correct / possible or not but


Yeh in my mind 'fail' is it finds a duplicate ---- that means I send an error to myself but I'm thinkng---- I would like to include the duplicate(s) that it found (which will be one or two rows) in my error report so I will know it found duplicate txn_id or duplicate email or both

but I don't know how to get that:-(

does that make sense

if nothing is found -- zero rows --- it goes on to insert stuff into DB


LT


$result stores what PHP calls a query resource.

hahah yeh I found that out by trying to include $result which at the time didn't make sense but I kinda guessed

Fumigator
12-03-2010, 06:57 AM
So if a fail is finding more than one row with the same txn_id, your query should be



SELECT COUNT(*)
FROM users
WHERE txn_id = $txn_id


Then see if the value fetched is > 1.

low tech
12-03-2010, 07:14 AM
Hi Fumigator

I think a fail is finding more than zero --- ie if it finds one its a fail ---- There should either be none or one ---- if one already exists in DB then its a fail.

BUT my problem is when it fails --- it means it found one (at most two)--- how do I get that one(or two) into my error report ??


Now the query does work -- it does fail if I send duplicate email or txn_id or both.

So example if I send duplicate txn_id 12235678

and it's already in DB

it will fail and send myself a notice but I want my error report to include what it found in DB ie duplicate 12345678 (or email or both)

it seems to make sense to me anyway hhaha



LT

Lamped
12-03-2010, 07:46 AM
Well, as abduraooft pointed out in the last thread I helped you with: If you create a joint unique index for txn_id and user_email, there can't be any duplicates. Perhaps that's a better way to go?

Edit: I just read your other thread. Nevermind :D

I'll see about taking a look later if no one else has - I have a busy day today.

low tech
12-03-2010, 08:13 AM
Hi Lamped

Yes as I said in the other post your solution worked very well. Thank you:-)

I just thought I could help myself by reporting to myself what duplicate had been found.

ie
txn_id
user_email
or
both

In truth they are unlikely(but not impossble) and since i'm very interested to learn and this is a real life situation ie mine:-) why not?


I can only think one stage at a time so everythign is changing as I face / discover next problem:-(


LT

low tech
12-04-2010, 12:49 AM
Hi

Well I've tried and tried and i've read stuff but nah I can't figure it out

I used this in my script

while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
echo $col_value ; // i changed this line around also but got nothing:-(
}
}

and tried to put $col_value in my error mail hahhahhaha nah didn't work

and i tried load of other crazy ways too hahahaa

so if anybody has any idea of how I should try to do this

i'm very interested and would love the help

I'd even be interested to know if what i'm trying to do is silly:-)

LT
ps:-)smile

Fumigator
12-04-2010, 03:04 AM
What happens when you place your query into PhpMyAdmin and run it?

low tech
12-04-2010, 04:48 AM
Hi

don't laugh i'm trying hahhahaha

This query put into PhpMyAdmin


SELECT txn_id, user_email FROM users WHERE txn_id='907856342' AND user_email='expirydate@paypalsandbox.com'
returns this as expected


table
txn_id user_email
907856342 expirydate@paypalsandbox.com

BUT if I try to add on this


while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
foreach ($line as $col_value) {
echo $col_value ; // i changed this line around also but got nothing:-(
}
}

it shouts syntax errors at me ---- also expected hahahhaa

since my real query also has this line


$result = mysql_query($checkquery, $Connect) or die("Duplicate txn id check query failed:<br>" . mysql_error() . "<br>" . mysql_errno());
and I think the while loop

or this (which I also playing with)


$num_rows = mysql_num_rows($result);
which should probably be below that line BUT if put that line in PhpMyAdmin of course it goes nuts again hahahahhahhaa

what should I be trying to do??

There must be a way to get that row information out of DB and into my error report.

LT

low tech
12-04-2010, 05:00 AM
Hi again

ok with this query (which will give me duplicate)


$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 (!mysql_fetch_array($result))


IN m else Ihave this


else{
// DUPLICATE: error notify
mail($notify_email, "VERIFIED DUPLICATED TRANSACTION or EMAIL", "$num_rows Rows\n\n

and in my error email I get this


1 Rows



BUT I don;t get the DETAILS of that row??????

ok I don't get it

:-(

LT

syncupsolutions
12-04-2010, 10:32 AM
I'm not sure I understand completely, but your query seems like it will die when it finds duplicates instead of returning all the information you need. And if you find more then one duplicate then I didn't see any way of returning that information at all. Try this, you may have to edit it a little:



<?php
$checkquery = "SELECT * FROM users where txn_id='".mysql_real_escape_string($txn_id)."' OR user_email='".mysql_real_escape_string($user_email)."'";
$result=mysql_query($checkquery,$Connect) or die(mysql_error());
$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);
}else{
//Whatever you do upon success.
}
?>

low tech
12-04-2010, 01:49 PM
Hi syncupsolutions

oh wow

amazing effort

thanks a million

can't play around with it now, but will definately try it asap

LT

ps I have lots n lots of errors because i'm just learning as I go --- but it's ok:-)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum