Solved

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

Posted on 2007-04-05
5
265 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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.

785 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