Solved

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

Posted on 2007-04-05
5
276 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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.

710 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