How to insert console.log(res) data to database using php mysqli

You can use fetch() for making HTTP requests. MDN Documentation here.

This code should work. Just replace the URL to the URL of your own PHP file! This example assumes you want to send the data as JSON.

/* ... */

ZoomMtg.getAttendeeslist({
  success (res) {
    if (res) {
      if (res.errorCode > 0 || res.errorMessage !== null || res.status === false) {
        return void console.error(res)
      }

      if (Array.isArray(res.result.attendeesList)) {
        console.log('Retrieved attendees list')

        const myUrl = 'https://myowndomain.com/upload_attendees_list.php'

        fetch(myUrl, {
          method: 'post',
          headers: {
            'Content-Type': 'application/json'
          },
          body: JSON.stringify(res.result.attendeesList)
        })
      } else {
        console.warn('Attendees list result was not an array!', res.result)
      }
    } else {
      console.warn('No result object in getAttendeeslist success handler')
    }
  },
  error (err) {
    console.error('Could not get attendees list!', err)
  }
})

/* ... */

Okay, so you’re accepting FormData in your PHP file, with the res key. Therefore we need to alter the JavaScript to something like this instead:

/* ... */
const myUrl = '...';
const form = new FormData()
form.append('res', res.result.attendeesList)

fetch(myUrl, {
  method: 'post',
  body: form
}).then(() => {
  console.log('The data was uploaded!')
}).catch(err => {
  console.error('HTTP request failed', err)
})
/* ... */

no…in upload_attendees_list.php how to get json.stringify(res) because its showing null…i dont want to use form data…i want to get json data to upload_attendees_list.php and do database connection and store the json data…

In upload_attendees_list.php:

// Get input data as JSON
$data = json_decode(file_get_contents('php://input'), true);

echo $data;

/* Now use the $data for inserting into db */

In the JavaScript file, use the previous code sample, the one with ’Content-Type’: ’application/json’.

Also, please sanitize the php input before using it in the SQL query!

thank you for your reply.its working after using json encode

$data = json_decode(file_get_contents(‘php://input’), true);
$newdata=json_encode($data);
echo $newdata;

1 Like

Yes, the ZoomMtg.getAttendeeslist() function returns an array in res.result.attendeesList. Therefore, an array is sent as JSON.

In your PHP file, you need to decode the JSON, which the code I sent does.

This gives you a PHP array of all the attendees. Then you have to loop through that array to insert each attendee one by one, if that’s what you want to do.

So your PHP file should probably look something like this:

<?php
$data = file_get_contents('php://input');
$attendeesList = json_decode($data, true);

print_r($attendeesList);

require("db/connect.php");

if (is_array($attendeesList)) {
  $DataArr = array();
  foreach ($attendeesList as $key => $attendee) {
    $username = mysql_real_escape_string($attendee["userName"]);
    
    $DataArr[] = "('$username')";
  }
  
  $sql = "INSERT INTO attendees (username) values ";
  $sql .= implode(",", $DataArr);
  
  echo $sql;
  
  $res = mysql_query($conn, $sql);
  
  if ($res) {
    echo "inserted";
  } else {
    echo "not";
  }
}
?>

Links:

This starts to look like StackOverflow lol.

Thank you …I will use this code and check it out…

1 Like

okay thank you i have changed code but working fine…

websdk unable to start video.Your camera has been occupied by other apps, please release the privilege and try again.how to start when i click on video…

attendee list not visible after admitting attendee and not storing data ,again i have to refresh page to insert,how to solve this problem

After participant admit by host…it’s not storing attendence to database once I refresh page it wil store to database …I don’t want to refresh…once admit by host to participate store name to database without refresh the page

Hi…
Atendee’s name not storing to dataabse once host admit to participate,through Gmail I invite each participate and url is https://us04web.zoom.us/j/76860445789?pwd=MUtBdGs5ZVFueG9VcTkxanRjYUplQT09
Automatically it won’t store name to database again I have to refresh but it’s not possible for all time…solution please

I think it all depends on where you call getAttendeeslist() and the fetch() request. Perhaps it would be easier if you could link to a GitHub page or something, so I can take a look at your code.

Can you show what your JavaScript code looks like now?

exactly same code I have used whatever u sent…but once user click on link it goes to either lounch website in browse or download zoom…once user enter his name and password it will wait for host to admin it…but the attendee name automatically not inserting it to database…

Have a look over here: getAttendeeslist() doesn't show attendees in console log only showing host name but not other attendees

Thanks for contributing to the Zoom Developer Community @daniel2! :slight_smile:

@yash.sakali, let me know if you have any additional questions.

-Tommy

1 Like

I can view participate after joining meeting but how do I insert participate to my database…can you help me to solve this issue?all user not joining from websdk so I don’t want to use getattendeeslist()…any other method tthanks in advance

Hey @yash.sakali,

Here is your answer:

Thanks,
Tommy

I am not getting how to use participate webhook…can you help me to get it…I need to insert participate to my database…thanks in advance

Hey @yash.sakali,

Here are the Webhook docs which explain how to use them:

Thanks,
Tommy

Hi, @sonyaxyz6 ,

Thank you so much for taking the time to contribute to the Zoom Developer Forum. Your valuable insight and expertise are highly appreciated by the entire community. The knowledge you have shared will undoubtedly prove to be beneficial to fellow members who come across this thread.

Given that this topic has been around for a while and might not be actively followed by everyone, I will proceed to close it. However, if there are individuals who are interested in continuing this discussion, I kindly request them to create a new topic. By doing so, they can provide a link to this thread, ensuring that the new discussion remains connected to the original one. This approach will not only help keep the conversation updated with the most current guidance but also align with the latest best practices in the Zoom developer community.

Once again, thank you for your valuable contribution and for being an active participant in our community. We truly value your input and look forward to your future contributions.