0

Following is my code

//FIRST UPDATE QUERY
$firstupdatequery = "UPDATE `register` SET suser ='1' ";
//Second UPDATE QUERY
$updater = "UPDATE `register` SET suser ='$suser',steamleader ='$steamleader',ipdate ='$ipdate',customer ='$customer',cperson1 ='$cperson1',mobile1 ='$mobile1',phone ='$phone',fax ='$fax',email ='$email',website ='$website',pincode ='$pincode',state ='$state',city ='$city',address ='$address',status ='$status',data_resource ='$data_resource',comments ='$comments',data_status ='$data_status',followup_date ='$followup_date',last_followup_date ='$last_followup_date',last_comment ='$last_comment',data_assign ='$data_assign',bank_id = '$bank_id' WHERE id = ".$getid."";

$exequery = $conn->query($updater);
if($exequery){
  if(mysqli_affected_rows($conn) > 0){
    //insert for followup recored
    echo "<pre>";
    print_r($conn);
    echo $conn->affected_rows;
    exit;
    //And than I am running another insert query here

this code shows if any row updated so i run the another insert query.but problem is when i press button without changing the any value still it mysqli object affected rows count to 1.

mysqli Object
(
    [affected_rows] => 1

Why this count to 1 even i didnt changed any value. *

NOTE: i am Updating one row above this code

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
  • Do you get the same result when you do this with SQL alone (=> `ROW_COUNT()`)? – Dormilich Mar 26 '18 at 10:44
  • When i am echo update and perform it manually so it returns `0 rows affected. (Query took 0.0650 seconds.)` –  Mar 26 '18 at 10:46
  • 1
    MySQL is dumb. It's so dumb that it won't read the previous data values unless you tell it too. So every time you submit an `update` mysql gos to work and just says "yup boss, i took your data and i put it in, give me a treat because I did so with no errors". If you want update to only update if the data is different, then you'll need to compare your input to your data and act accordingly. – IsThisJavascript Mar 26 '18 at 10:47
  • So what should i have to do –  Mar 26 '18 at 10:50

1 Answers1

2

There is a trick, I would call it a dirty one, but I know no cleaner way to do so

list($matched, $changed, $warnings) = sscanf($conn->info, "Rows matched: %d Changed: %d Warnings: %d");
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • You mean to say `[info] => Rows matched: 1 Changed: 1 Warnings: 1` Which returns by `mysqli Object` –  Mar 26 '18 at 10:59