I am making a javascript counter of how many online users are seeing a question. Example: Pedro and Juan and one more person are seeing this question. The variable user_online
stores the names of online users. I use jquery because through AJAX I want to refresh online users.
var user_online = ["Pedro", "Juan", "Carlos"];
My question is how do I, when pressing a button on the page, send the value of this variable, collecting the values in PHP and saving it in the database using mysqli , following this structure:
id User_Online
---- ---------------------
1 Pedro, Juan, Carlos
To send an array from JavaScript, using jQuery AJAX, receive it in PHP and save it in MySQL, the following steps are used:
1. Suppose an HTML like this:
2. In
grabarbd.js
, send the array by POST3. In
grabarbd.php
, the value is received and recorded in the baseNote: This is an example showing basic functionality. The treatment of possible errors must be added.