Hi guys, i'm tryng to check available when update a record! so i'm getting that the record is available!
Bellow my class and my proccess

//this is my function i use inside of my class

function getInfonupdate($display_name) {
        $query = $this->link->query("SELECT * FROM tbl_types WHERE display_name != '$display_name'");
        $rowcount = $query->rowCount();
        if ($rowcount == 0) {
            $result = $query->fetchAll();
            return $result;
        } else {
            return $rowcount;
        }
    }
    //and my proccess is 

     $check_availablity = $types->getInfonupdate($display_name);
                    if ($check_availablity == 0) {
                      $update = $types->editTypes($id_type_group, $display_name, $description, $date_modified, $user_modified, $type_id); 
                    if ($update == 1) {
                    $_SESSION['success'] = "<div class='alert alert-success alert-dismissable'>
        <i class='fa fa-check'></i>

   <button type='button' class='close' data-dismiss='alert' 

      aria-hidden='true'>

      &times;

   </button>
New Type {$display_name} has been successful Updated!

</div>'";
                    header('Location: ../edit_type.php?success');

            }
        }

So when i run i get the user is olready added! like i count update a query!
And i've no idea how to check when update a record!

If you need to know if the row exists you should query the database for that row only.
SELECT COUNT(display_name) FROM tbl_types WHERE display_name = '$display_name'

Now you're get a zero or 1 which is easy to check so you know if you need to update or insert.

Hi Hericles, Thanks for you help.
But this query is only to count columns, you cant count values.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.