• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 292
  • Last Modified:

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

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
  • 3
  • 2
1 Solution
St_Aug_Beach_BumAuthor Commented:
oh, and I'm using php 4.3.3
$changed = mysql_affected_rows();

if($changed==0) {


St_Aug_Beach_BumAuthor Commented:
Thank you.

Would I put that after the foreach statement is closed?
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.
St_Aug_Beach_BumAuthor Commented:
Thank you Steelseth12.

Got it :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now