Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

860 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