How to create function to "change" and "delete"?

Asked

Viewed 72 times

0

I have a table where displays the "data" already registered, and for each data has the option "edit" and "delete".

Now I am in doubt how to delete and change the chosen data. I would need a specific page to "change" ?

The code for "entering" data is like this:

        public function clientes( array $data )
    {
        if( !empty( $data ) ){

            // Trim all the incoming data:
            $trimmed_data = array_map('trim', $data);



            // escape variables for security
            $nomecliente = mysqli_real_escape_string( $this->_con, $trimmed_data['nomecliente'] );
            $cpf = mysqli_real_escape_string( $this->_con, $trimmed_data['cpf']);
            $contatocliente = mysqli_real_escape_string( $this->_con, $trimmed_data['contatocliente']);
            $ruacliente = mysqli_real_escape_string ($this->_con, $trimmed_data['ruacliente']);
            $numeroendereco = mysqli_real_escape_string ($this->_con, $trimmed_data['numeroendereco']);
            $complementocliente = mysqli_real_escape_string ($this->_con, $trimmed_data['complementocliente']);
            $bairrocliente = mysqli_real_escape_string ($this->_con, $trimmed_data['bairrocliente']);
            $cidadecliente = mysqli_real_escape_string ($this->_con, $trimmed_data['cidadecliente']);



            $query = "INSERT INTO clientes (idClientes, nome, cpf, contato, rua, numeroEndereco, complemento, bairro, cidade)
                VALUES (NULL, '$nomecliente', '$cpf', '$contatocliente', '$ruacliente',
                                                                        '$numeroendereco', '$complementocliente', '$bairrocliente', '$cidadecliente')";
            if(mysqli_query($this->_con, $query)){
                mysqli_close($this->_con);
                return true;
            };
        } else{
            throw new Exception( ERRO );
        }
    }

It is possible to do everything in the same function?

  • 3

    Hello Anonn, your question needs to be more specific, there are too many doubts in it, and more importantly, it seems to me that you have not yet made one CRUD (inclusion/consultation/update/exclusion) in php. I suggest you see some examples on the Internet, this one is a : https://github.com/glaucia86/projeto.crud.php As for your questions, see the example above and create one Function for each operation

  • You need a function like this where instead of doing INSERT, do another action such as UPDATE and DELETE

  • A if($_POST['deletar'] { DELETE .....} A if($_POST['editar'] { UPDATE .....} would not solve?

  • Ricardo Pontual, the screens are already done, what is missing are the functions to delete and change. The link file to open without downloading? Leo Caracciolo, among the same function ?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.