Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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