Solved

if mysql update fails to find row, email it to me. How can I do this?

Posted on 2007-04-05
5
263 Views
Last Modified: 2011-09-20
Right now I have an array of data coming in and I use it to update mysql like this:
---------------------------
foreach ($rows as $row) {
        $data = explode(',', $row);

 //update pricetoday, rebates, afterrebates where name and carrier match

        $uqry = "UPDATE cellphones SET pricetoday = '{$data[3]}', rebates = '{$data[4]}', afterrebates = '{$data[5]}' WHERE name ='{$data[1]}' AND carrier = '{$data[2]}'";

$res = mysql_query($uqry) or die(mysql_error());     }
--------------------------------

What I would like to do is when there is a row that doesn't match (for example, if it tried to match 'sample phone' and 'sample carrier' and there is no match in the database), that information is emailed to me.

So, after the update line, if no match was found, put that info into an array (in case there is more than one non-match) and then send me the info:

mail("chris@mysite.com","Cell Phone update","

These phone/carrier combos need to be added to the db:

print_r ($add[0]);
//results would be like this:
//sample name, sample carrier
//sample name1, sample carrier1, etc

  ","From:Cell Phone Update <admin@mysite.com>");


Thank you for any assistance,     Chris
0
Comment
Question by:St_Aug_Beach_Bum
  • 3
  • 2
5 Comments
 

Author Comment

by:St_Aug_Beach_Bum
ID: 18859576
oh, and I'm using php 4.3.3
0
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 18859894
$changed = mysql_affected_rows();

if($changed==0) {

   SEND MAIL HERE

}
0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 18859948
Thank you.

Would I put that after the foreach statement is closed?
0
 
LVL 20

Expert Comment

by:steelseth12
ID: 18859970
you will put it after a mysql_query is executed inside the loop .... if you put it outside the loop it will only check for the last update.
0
 

Author Comment

by:St_Aug_Beach_Bum
ID: 18860183
Thank you Steelseth12.

Got it :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now