Tell me how you can write, please give an example of the function (ajax), which when you click on the button, sends the user ID to the PHP script. PHP script adds the value (the name of the authorized user and the name of the user to the page of which he entered) in the database. Thank you in advance!

  • one
    @ raptor96, According to the rules of the forum, questions should not be reduced to proposals to perform the work. - spoilt

1 answer 1

$.post('script.php', {id: 1}); // jQuery 

In PHP:

 <?php $id = $_POST['id']; $username; $a_username; mysql_query("INSERT INTO `table` (`username`, `a_username`) VALUES ('{$username}', {$a_username})"); ?> 
  • So callback. $ .post ('script.php', {id: 1}, function (data) {element = $ ('# status'); element.html ('Success'); setTimeOut (function () {element.hide ( );}, 5000); // 5000 - after how many milliseconds do you need the message to disappear}); - Shevsky