Add data to a database via a link

Asked

Viewed 654 times

-1

I did a quick search but did not find, so I’m posting here. Well, here’s the thing, I want when the person click one link (in the case <a href=.......>inserir</a>) execute the following SQL code:

INSERT INTO `rooms` (`id`, `roomtype`, `caption`, `owner`, `description`, `category`, `state`, `users_now`, `users_max`, `model_name`, `public_ccts`, `score`, `tags`, `icon_bg`, `icon_fg`, `icon_items`, `password`, `wallpaper`, `floor`, `landscape`, `allow_pets`, `allow_pets_eat`, `allow_walkthrough`, `allow_hidewall`, `wallthick`, `floorthick`, `achievement`) VALUES
('', 'private', '', '', 'Novo modelo de quarto', '1', 'locked', '0', '100', 'model_recep2', 'hh_room_nlobby2', '538', '', '12', '0', '', '', '0.0', '407', '0.0', '0', '0', '1', '1', '-2', '-2', '0');

From what I saw on the Internet js, I even created a page with the hash $inserirroom and this SQL above, but I don’t know how to do this so that by clicking on link such code is executed. Thank you!

  • 2

    Simply point the href of your link to the php that does this Insert. Or there’s something I don’t understand?

1 answer

2


There are several ways to do this, one is like the our colleague put: simply point out the href from your link to PHP that does this Insert.

Another way is to run asynchronously using Javascript AJAX.

You can do this easily using the method .get or .post jQuery:

fucntion incluir(){
    $.post( "ajax/incluir.php", function( data ) {
      console.log(data);
    });
}

This date parameter is the return of the file .php, can be a echo 'salvo com sucesso';.

Remember to call this method incluir Javascript in the event (can be onclick) of your element (in your case a link) but could be a button too.

Browser other questions tagged

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