I'm trying to make a little project for adding friends. When you click the add friend button you are sending an Ajax call with the friend id & username (they are the id and name attributes of each add button) to the add.php file. (The mysql structure is: 1 users table + X tables named the user's name(columns: friendid, ispending)) In the PHP file there are only 2 MySQLi queries: Here is the code for the add file:
session_start();
$friendid = $_POST['id'];
$myname = $_SESSION['username'];
$friendname = $_POST['name'];
$myid = $_SESSION['id'];
$add = new Mysqlconnect();
$add->db->query("INSERT INTO $myname VALUES($friendid, 'yes')");
$add->db->query("INSERT INTO $friendname VALUES ($myid, 'yes')");
$add->db_Close();
The Mysqlconnect class is required i just didn't want the code here to be too long. Here's the Ajax call:
$('.add').click(function(){
var name = $(this).attr("name");
var id = $(this).attr("id");
$.ajax({
type: "POST",
data: "&name="+name+"&id="+id,
url: 'add.php',
success: function(){
alert("success");
}
});
});
THE PROBLEM : When I click "add friend" it does alert "success" but only one table gets updated everytime or even no table at all. Though one time I clicked it and it did work (I did not change the code that time, I tried clicking like every 20 seconds).
How can I solve this? strong>